C programming slide c02

2,440 views

Published on

1 Comment
10 Likes
Statistics
Notes
No Downloads
Views
Total views
2,440
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
92
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide

C programming slide c02

  1. 1. Prepared by:-<br />PRADEEP DWIVEDI (pur. B.TECH-IT)<br />FROM-<br />HINDUSTAN COLLEGE OF SCIENCE &TECHNOLOGY<br />Mob-+919027843806<br />E-mail-pradeep.it74@gmail.com<br />C-PROGRAMMING SLIDE-2<br />Monday, August 30, 2010<br />1<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />
  2. 2. <ul><li>Sample program.
  3. 3. Format of simple c program.
  4. 4. Constant ,variable and data types.
  5. 5. C tokens.
  6. 6. Some program and explanations.</li></ul>TOPIC:-<br />Monday, August 30, 2010<br />2<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />
  7. 7. SAMPLE PROGRAM(SEE-SAMPLE.C)<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />3<br />#include<stdio.h><br />#include<conio.h> <br />void main()<br />{<br />clrscr();<br />printf(“hello, I am pradeep”);<br />getch();<br />}<br />
  8. 8. #include directve<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />4<br />c programs are divided in to modules or functions.<br />some functions are written by users, like us , and many other are stored in the c library.<br />library functions are grouped category-wise and stored in different files known as header files.<br />if we want to access the function stored in the library , it is necessary to tell the compiler about the file to be accessed.<br />this is achieved by using the preprocessor directive #include.<br />
  9. 9. TERMs RELATED TO PROG<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />5<br />stdio.h:- standard input output header file<br />scanf() printf()<br />conio.h:-consol input output header file.<br />clrscr() getch()<br /> (clear screen) (pause screen)<br /><ul><li>.h extension for header file.</li></li></ul><li>TERMs RELATED TO PROG<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />6<br />void is a return type that return nothing (blank return type)<br />main() is a predefine function that start the execution of our program.<br />with out main() function no program can be executed.<br />NOTE:-<br />each and every function always followed by parentheses sign. ()<br />
  10. 10. SAMPLE PROGRAM(SEE-SAMPLE.C)<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />7<br />this program when executed will produce the following output. <br />hello, I am pradeep<br />the first inform that the execution of our program begin at this line.<br />the main is a predefine(special) function used by the c system to tell the compiler where the program starts. <br />every program must have exactly one main function.<br />if we use more than one main function the compiler can not understand which one marks the beginning of the program.<br />
  11. 11. SAMPLE PROGRAM(SEE-SAMPLE.C)<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />8<br />the opening brace { in the second line marks the beginning of the function main() and the closing brace } in the last line indicates the end of the function.<br />printf() is a standard predefine c function for printing output.<br />predefined means that it is a function that has already been written and compiled and linked together with program at the time of linking.<br />the printf function every thing between the starting and the ending quotation marks to be printed out.<br />semicolon(;) sign is called terminator.<br />every statement in c should end with a semicolon.<br />
  12. 12. TERMs RELATED TO PROG<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />9<br />clrscr(); is a predefine function that clear the output screen.<br />it comes from conio.h header file.<br />getch(); is also a predefine function which is used to pause the output screen. <br />
  13. 13. FORMAT OF SIMPLE C PROGRAM<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />10<br />main() function name<br />{ start the program<br />} end the program<br />program statements (body)<br />
  14. 14. CHARACTER SET<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />11<br />The character in c are grouped into the following categories.<br />Letters<br />Digits<br />Special characters<br />White space<br />
  15. 15. C TOKENS<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />12<br /> in a passage of text individual words and punctuation are called tokens.<br />Similarly, in c program the smallest individual units are known as c tokens. <br />
  16. 16. CONSTANTS<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />13<br />
  17. 17. VARIABLES<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />14<br />Variables are a place holder that holds the place in computer memory for the value.<br />Because its value may be varied that’s why it is known as variable.<br />int a; (this is called variable declaration).<br />data type variable.<br />int a=10;(this is called initialization of variable. <br />
  18. 18. DATA TYPES<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />15<br />data type decide that what kind of value should be held by the variable.<br />in c data types are classified into three categories.<br />primary(or fundamental data) types.<br />derived data types.<br />user defined data types.<br />
  19. 19. DATA TYPES<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />16<br />
  20. 20. Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />17<br />DATA TYPES<br />
  21. 21. DATA TYPES<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />18<br />void type:-<br />void has no value.<br />this is usually used to specify the type of function.<br />
  22. 22. KEYWORDS AND IDENTIFIERS<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />19<br />KEYWORDS are the reserve words those are having some predefine meaning and those are only use for their predefine meaning.<br />all keywords in c are in lower case.<br />in c we have 32 keywords.<br />eg, if, else, for, while, char, int etc.<br />IDENTIFIERS refers to the names of variable, function and arrays.<br />
  23. 23. NAMING RULES AND CONVENTIONS FOR THE VARIABLE NAME(IDENTIFIERS)<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />20<br />a variable name can be anything but it should be short and meaningful.<br />a variable name can not start with a digit. it must be started with an alphabet letter. but a variable name can be followed by n number of digits.<br />it can be started with an underscore sign(_) also.<br />we can not use any special symbol like @,#,*,& in a variable name.<br />we can not use any space in a variable name. if we are having mare than one word in a variable name and space is required that time we can use the underscore(_) sign between them.<br />my_name ,myName.<br />any keywords can not be a variable name. <br />
  24. 24. prog:1<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />21<br />/*WRITE A PROGRAM TO ACCEPT A NUMBER FROM THE USER AND PRINT THEM*/<br />#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />int number;<br />clrscr();<br />printf("Enter a number");<br />scanf("%d",&number);<br />printf("the number is: %d",number);<br />getch();<br />} <br />
  25. 25. TERMs RELATED TO PROG<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />22<br />printf() is a predefine function with the help of that we can print the data in any specified format or agates if it is in double quotes. (“ “);<br />scanf() is again a predefine function that can accept data in any specified format.<br />
  26. 26. FORMAT STRING<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />23<br />format string is used to specify the format of the data .<br />these are following type of:-<br />%d (decimal)<br />%f (float)<br />%c (character)<br />%s (string)<br />%x (hexadecimal)<br />
  27. 27. ADDRESS OPERATOR(&)<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />24<br />It is used to keep the address of that place where the value is placed.<br />
  28. 28. prog4<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />25<br />/*write a program to convert a character to its ascii value*/<br />#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />char alph;<br />clrscr();<br />printf("Enter a character");<br />scanf("%c",&alph);<br />printf("value of character is %c ",alph);<br />printf("value of character equivalent is %d ",alph);<br />getche();<br />}<br />
  29. 29. SOME POINTS<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />26<br />note:- each and every character is internally treated as an integer.<br />getch(); is a predefine function that accept a character on the output screen . it just wait for a character.<br />getche(); is having same functionality like getch() function but different is that it displayed the accepted character on the consol screen.<br />getchar(); is also a predefine function that accept a character but that character must be followed by the enter key.<br />note:-drawback of scanf function is that it never accept the space. <br />
  30. 30. COMMENTS<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />27<br />commets are used to give the better readability of a program.<br />at the time of program execution comments are ignored by the compiler.<br />these are two types of:<br />//single line comments<br />/* multiple line <br />comments */<br />note:-we can not use nested comments. <br />
  31. 31. RETURN TYPE<br />Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />28<br />It decide what kind of value should be returned by the function.<br />if we don’t use any return type before the function that time by default there is int.<br />return is a keyword with the help of that we can return a value and a value is always return where the function is being called. <br />
  32. 32. Monday, August 30, 2010<br />PRADEEP DWIVEDI [pur.B.TECH-IT]<br />29<br /> THANKS<br />

×