1 / 133

C Programming

C Programming. A. S. D. F. K. L. ;. Computer system. Monitor. CPU. Key Board. mouse. Parts of a computer Processor, memory, hard disk, input, output. In memory both the program lines and variables are kept

lazaro
Download Presentation

C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C Programming

  2. A S D F K L ;

  3. Computer system Monitor CPU Key Board mouse

  4. Parts of a computer Processor, memory, hard disk, input, output. In memory both the program lines and variables are kept Action is taking place in processor and results are stored there in the memory. Even the output is given in the output window and flipped back to the edit window

  5. Computer system Monitor CPU Key Board mouse

  6. Computer system memory Monitor Hard disk processor CPU Key Board mouse

  7. Steps in executing a code Write the code (source code) Compile the source code If errors go back to edit and correct and repeat compiling If no errors, the compiler has generated the machine (object code) Run the (object) code and so get the results

  8. void main() { int a = 4,b =7 , c; c = a + b; printf(“ sum is %d” ,c); } 4 a 7 b junk c

  9. void main() { int a = 4,b =7 , c; c = a + b; printf(“ sum is %d” ,c); } 4 a 7 b 11 c

  10. void main() { int a = 4,b =7 , c; c = a + b; printf(“ sum is %d” ,c); } 4 a 7 b 11 c Sum is

  11. void main() { int a = 4,b =7 , c; c = a + b; printf(“ sum is %d” ,c); } 4 a 7 b 11 c Sum is 11

  12. void main() { int a = 4,b = 7, c; c = a + b; printf(“ %d + %d is %d “,a,b,c); } 47 0 4 a 7 0 11 b 11 junk c 4 + 7 = 11

  13. What is programming? Making the computer work as we want it to work Getting things done by the computer We write the program in the memory and make the processor work it out

  14. What is programming? Programming is making the computer work as we want it to. ie. we will have to talk to a machine. Some syntax is there. Only a few syntaxes to be byehearted. A series of instructions to the processor, so that it can do the entire work, without any difficulty. Instructions in a tape recorder or MP3 player to make milk tea!

  15. How do we make it work? We keep a program in memory and ask the processor to execute line by line It is like a boy following the instructions given to it, systematically and quickly, but without any common sense or mind reading capability. Fast unlike us, obedient unlike us and having no common sense like us?!

  16. Vehicle v/s program If a new vehicle, draw, expert opinion, (----- )finally build and run. But this expert (compiler) will build it! So if there is a modification, show to expert/(compile) and only then run

  17. The compiler is like an expert Compiler is the expert who/which tells whether the syntax is correct! If not, we are to correct and again submit. Finally build and test run. Compiler will compile too! Compiler is also without common sense at times. Logical errors! Compiler will not correct logical errors. So to know what is happening, print the results, in between or check the values of variables.

  18. In Input and output mechanism If we are to see the result, project them onto the screen (printf) %d is a place holder in that order But the result screen will flip back to edit and so get it back by alt f5 order to get values from the key board, scanf

  19. Variables and memory address All the variables to be used must be declared (and so given locations). The dissection of a frog! The memory address is the uniquely identifying method. In a college, register number, in a town, the address,

  20. The operations possible Different operators, + - * / but % is also there! Integer on integer will give only an integer.

  21. Some suggestions Meaningful variable names and function names Do proper indentation Results printed should be made meaningful Do hand tracing Draw flow charts! Feel free to ask doubts, loud clear and smart Free to ask. Loud and smart Please learn blind typing at the earliest Note that there are two types of slashes in KB Use the home and end keys wherever required Make your own changes and see whether the expected results are obtained

  22. Neither copy nor mug up Do a hand tracing of the programs for understanding on the one side and to find out the mistakes on the other side Spend some time to plan the program using algorithm or flow chart Be sure that it is logic and no magic. Avoid printing results inside the loops Hard code first and then go for soft coding Get the addresses from the computer and draw a memory map

  23. There are different slashes, \n, \t.... // /* and */ The operations possible Different operators, + - * / but % is also there! Integer on integer will give only an integer. The operator precedence issues. 5+2 * 3 = 11 v/s (5+2) * 3 = 21 Right to left and left to right 2/4*3 v/s 2*3/4 X+1 % 5 v/s (x+1) % 5;

  24. See Programming in C #include<stdio.h>// header file inclusion void main() { printf(“Let Us C”); }

  25. See Programming in C #include<stdio.h> void main()//a must for any C program to work { printf(“Let Us C”); }

  26. See Programming in C #include<stdio.h> void main()//see the function braces { printf(“Let Us C”); }

  27. See Programming in C #include<stdio.h> void main()//see the function braces // there is a space between void and main // main can not be capital! ie. C is case sensitive { printf(“Let Us C”); }

  28. See Programming in C #include<stdio.h> void main()//function header { printf(“Let Us C”); }

  29. See Programming in C #include<stdio.h> void main()//function header { printf(“Let Us C”); } If there is a head, there shall be a body after/below the head

  30. See Programming in C #include<stdio.h> void main()//function header {// body begins printf(“Let Us C”); }// body ends If there is a head, there shall be a body after/below the head

  31. See Programming in C #include<stdio.h> void main()//function header { printf(“Let Us C”);// end of an instruction }

  32. Every program should have this function and only one main function. No capital M please DISSECTION of a basic C program Function braces, simple braces, ellipse. This is to hold or receive parameters or arguments. Presently it is holding nothing Function body begins main() { printf(“Welcome to see the sea of C”); } Function body ends printf function takes/holds necessarily one argument which is a string. Starting and ending by ” ” End of an instruction is signaled by ; Only one instruction or statement

  33. #include<stdio.h> printf should have a prototype ? main() { printf(“\n \tWelcome to see the sea of C”) } ; } We can add escape sequences and format specifiers in the string Statement missing Compound Statement missing

  34. Welcome to see the sea of C See that C is Ecstatic #include<stdio.h> main() { printf(“\n \tWelcome to see the sea of C”); printf(“\n See that C is Ecstatic” ); } Un-terminated string or character constant

  35. See Programming in C #include<stdio.h> void main() { printf(“Let Us C”); }

  36. See Programming in C Let Us C #include<stdio.h> void main() { printf(“Let Us C”); }

  37. See Programming in C #include<stdio.h> void main() { printf(“Let Us \nC”); }

  38. See Programming in C Let Us C #include<stdio.h> void main() { printf(“Let Us \nC”); }

  39. See Programming in C #include<stdio.h> void main() { printf(“Le\tt Us C”); }

  40. See Programming in C Le t Us C #include<stdio.h> void main() { printf(“Le\tt Us C”); }

  41. See Programming in C #include<stdio.h> void main() { printf(“Let Us C\bK”); }

  42. See Programming in C Let Us K #include<stdio.h> void main() { printf(“Let Us C\bK”); }

  43. See Programming in C #include<stdio.h> void main() { printf(“Let Us C\rG”); }

  44. See Programming in C Get Us C #include<stdio.h> void main() { printf(“Let Us C\rG”); }

  45. See Programming in C #include<stdio.h> void main() { printf(“Let Us C\a”); }

  46. See Programming in C Let Us C #include<stdio.h> void main() { printf(“Let Us C\a”); }

  47. See Programming in C: Use of Variables #include<stdio.h> void main() { a = 5; printf(“a = a”); }

  48. See Programming in C: Use of Variables #include<stdio.h> void main() { a = 5; printf(“a = a”); } Undefined symbol ‘a’ in main

  49. See Programming in C: Use of Variables #include<stdio.h> void main() { int a; printf(“a = a”); } //integer: used for counting Whatever you use should be brought in beforehand! The dissection of a frog, or brisk physics practical and instruments are damaged!

More Related