1 / 106

Introducing the ‘c’ Programming language

Introducing the ‘c’ Programming language. What is ‘C’ Programming Language ?. ‘C’ is a general purpose procedural programming language. It is developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Denis Ritche. ‘C’ is a Mid Level Language.

geneva
Download Presentation

Introducing the ‘c’ Programming language

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. Introducing the ‘c’ Programming language VINAY KUMAR GUPTA

  2. What is ‘C’ Programming Language ? ‘C’ is a general purpose procedural programming language. It is developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Denis Ritche. ‘C’ is a Mid Level Language. RAKESH ANAND

  3. Getting started with ‘C’ language. Steps in learning English language :- Communicating with a computer involves speaking the language the computer understands, which immediately rules out English as the language of communication with computer. However, there is a close analogy between learning English language and learning ‘C’ language.The method of learning English and learning ‘c’ language are given below :- Steps in learning ‘ C ’ language :- Alphabets ,Digits, Special symbols Character set Word Constants, Variables, Keywords Sentence Instructions Paragraph Programs VINAY KUMAR GUPTA

  4. The character set :- Constants :- Special Symbols :- =,+,-,*,/,%,>,<, ~, ‘,!,@,#,^,&,( ),|,?,:, [ ] , { } , ; , ” ,etc. A constant is a quantity that doesn’t change. e.g:- 10,20,30 etc. Alphabets :- a to z , A to Z Digits :- 0,1,2,3,4,5,6,7,8,9 Variables:- A quantity(constant) which can be stored at a locations in the memory of the computer. A variable can be considered as a name given to the location in memory where this constant is stored. e.g :- x=10; y=10;Here x and y is the variable. VINAY KUMAR GUPTA

  5. Some specific meaning in its dictionary. Such as :- +,-,*,/, int , float , char , etc. It is defined by the user. RAKESH ANAND

  6. TOKENS : - It is the smallest unit of the sentence or statement. Operators are special symbol who have an special meaning in arithmetical or logical expression. Such as :- + , * , - , / , % , ! , ! = , = = , > , < , < = , > = etc. { s = x + y ; P = x * y ; } “ ;” ,” { }” and “ , “ are seperators. It is used for seperates the tokens. Literals(constant):- literal are fixed value of the identifer. Such as :- x = 10 or nm = “ram”. Here 10 and ram are literals. Keywords are reserved words who have special meaning in the ‘C’ library. e.g :- int,float,char etc. It is always written in small letter. The total number of the keywords is 32. It is the memory location name where we can store a value at a time. e.g :- x = 5 , Here x is a identifier. RAKESH ANAND

  7. RAKESH ANAND

  8. RULES FOR NAMING IDENTIFIER : - 1. It can have maximum of 32 characters, but first eight character should be unique. Such as :- Student_no and student_name will be treated as same name because first character is not unique. 2 . First character should be an alphabet or under score (Hypen with sift). e.g : - s1 , _s etc. Don’t write such as :- 1s , -s etc. 3 . No special symbols are used in identifier except underscore. e.g : - roll_no , r_home etc. Don’t write like this :- roll-no , roll.no etc. 5 . Lower case and Upper case alphabet are significant. e.g : - x , y are different from X , Y . 4 . Identifier can’t be a keyword. RAKESH ANAND

  9. [ C ++ , C # , JAVA ETC. ] [OOPS] OBJECT ORIENTED PROGRAMMING LANGUAGE. IN THIS METHOD FIRST U D F AND THEN MAIN ‘ C ‘ IS A PROCEDURAL PROGRAMMING LANGUAGE. [ BASIC , COBOL , FOXPRO ETC. ] IN THIS METHOD FIRST MAIN AND THEN U D F RAKESH ANAND

  10. STRUCTURE OF THE ‘ C ‘ PROGRAM IT IS AN OPTIONAL ENTRY. FOR THIS WE USE COMMENTS [/* STATEMENT */] IT IS AN OPTIONAL ENTRY. SUCH AS :- #include <stdio.h> #include <conio.h> etc. IT IS AN OPTIONAL ENTRY. FOR THIS , WE USE “ && FOR AND “ , “ NULL FOR 0 “ , “ || FOR OR “ ,ETC. IT IS MANDATORY ENTRY. IT IS AN OPTIONAL ENTRY. IF YOU WANT TO MAKE PROCESS. RAKESH ANAND

  11. STRUCTURE OF MAIN FUNCTION RAKESH ANAND

  12. ASSIGN VALUES OR PUT VALUES OF THE VARIABLE. SUCH AS :- int x = 10; Float y = 30.45; etc. PRINT IT MEANS OUTPUT OF THE PROGRAM. VARIABLE DECLERATION . SUCH AS :- int x; float y; etc. PROCESS (LOGICAL OR ARTHIMETICAL). SUCH AS :- S = X * Y; if( x > y) etc. RAKESH ANAND

  13. RAKESH ANAND

  14. DATA IS STORED IN REAL FORM. SIZE IS BASICALLY 4 BYTES . DATA CAN BE STORED TILL 32 BITS. DATA IS STORED IN REAL OR INTEGER FORM BOTH. SIZE BASICALLY 8 BYTES. DATA CAN BE STORED TILL 64 BITS. FORM IN INTEGER. SIZE BASICALLY 2 BYTES, DATA CAN BE STORED TILL 16 BITS.(FIRST BIT RESERVES FOR SIGN BIT). VALUE VARY FROM -32767 TO +32768 DATA IS STORED IN CHARACTER(ENGLISH ALPHABET) FORM. SIZE BASICALLY 1 BYTE. RAKESH ANAND

  15. SIZE IS 2 BYTES. DATA CAN BE STORED TILL 15 BITS AND ONE BIT IS FOR SIGN ( + OR -). IN SIGNED INT ,VALUE OF THE DATA WILL VARY FROM -32767 TO +32768.(i.e. 215 ) AND UNSIGNED INT THE SIZE OF THE DATA IS 216. SIZE IS BASICALLY FOUR BYTES. IN SIGNED LONG INT , DATA CAN BE STORED TILL 0 TO 231 VALUEAND IN UNSIGNED LONG INT , DATA CAN BE STORED TILL 0 TO 232 VALUE. RAKESH ANAND

  16. SIZE IS BASICALLY 4 BYTES. IN SIGNED FLOAT ,DATA CAN BE STORED TILL 231VALUE AND IN UNSIGNED FLOAT , DATA CAN BE STORED TILL 232 VALUE. SIZE IS BASICALLY 8 BYTES . IN SIGNED LONG FLOAT , DATA CAN BE STORED TILL 263 VALUE AND IN UNSIGNED LONG FLOAT , DATA CAN BE STORED TILL 264 VALUE. RAKESH ANAND

  17. SIZE IS BASICALLY 10 BYTES (80 BITS). IN SIGNED LONG DOUBLE , DATA CAN BE STORED TILL 279 VALUE AND IN UNSIGNED LONG DOUBLE , DATA CAN BE STORED TILL 280 VALUE. SIZE IS BASICALLY 8 BYTES( 64 BITS). IN SIGNED DOUBLE , DATA CAN BE STORED TILL 263 VALUE AND IN UNSIGNED DOUBLE , DATA CAN BE STORED TILL 264 VALUE. RAKESH ANAND

  18. DATA TYPES AND THEIR KEYWORDS :- DATA TYPE KEYWORD EQUIVALENT Character char Unsigned character unsigned char Signed character signed char Signed integer signed int (or int) Unsigned integer unsigned int Signed short integer signed short int ( or short int) Signed long integer signed long int ( or long int) Unsigned short integer unsigned short int Unsigned long integer unsigned long int Floating point float Double precision floating point double Extended Double precision floating point long double RAKESH ANAND

  19. RAKESH ANAND

  20. HOW TO DECLARE A VARIABLE SYNTAX :- DATA TYPE VARIABLENAME ; DATA TYPE VARNM1,VARNM2,VARNM3,……… ; IT IS USED FOR ONE VARIABLE DECLERATION OF ONLY ONE DATA TYPE. EXAMPLE:- int x ; int y; etc. IT IS USED FOR DECLERATION OF MANY VARIABLES OF SAME DATA TYPE. EXAMPLE :- int x,y; float s,p; etc. RAKESH ANAND

  21. RAKESH ANAND

  22. IT MEANS , YOU CAN ASSIGN A VALUE OF A VARIABLE AFTER RUNNING THE PROGRAM. FOR THIS INITIALIZATION, WE USE scanf(“ “ ); KEYWORD. THE SYNTAX OF THE SCANF( ) KEYWORD :- Scanf(“type specifier”,&variablename); int x ; &x |----|----|-----|----|----|----|------| |----|----|-----|----|----|----|------| ^0 1 2 3 4 5 6 NOTE :- “ & “ IS GENERALLY USED FOR PUTTING THE VALUE OF A VARIABLE IN CERTAIN PLACE. IT MEANS YOU CAN ASSIGN A VALUE WITH VARIABLE DECLERATION ( SUCH AS :- int x = 10;) OR AFTER THE VARIABLE DECLERATION(SUCH AS:- int x; X = 10; IT IS ALSO CALLED COPY A VALUE. AFTER THE DECLERATION , BY DEFAULT VALUE OF THE VARIABLE IS GARBAGE.) RAKESH ANAND

  23. COMMONLY USED scanf FORMAT CODES :- CODE MEANING %c read a single character %d read a decimal number %e read a floating point value %f read a floating point value %g read a floating point value %h read a short integer %i read a decimal, hexadecimal of octal number %o read an octal number %s read a string %u read an unsigned decimal number %x read a hexadcimal integer %[..] read a string of word(s) RAKESH ANAND

  24. TYPE SPECIFIER :- DATA TYPE TYPE SPECIFIER integer ------------- int %d long int %ld float ------------- float %f long float %lf double ---------- double %ld or, %lf character --------- char %c string ----------- char %s PRINTF ( ) KEYWORD :- IT IS USED FOR PRINTING SOME TEXT OR MAKING GOOD OUTPUT OF THE PROGRAM. int x ; [ -------- decleration ] printf(“ enter the no.”); scanf(“%d”,&x); [-------- run time initialization ] SYNTAX OF printf ( ) KEYWORD :- printf (“ statement “); RAKESH ANAND

  25. RAKESH ANAND

  26. PROCESS (ARITHEMETICAL AND LOGICAL) :- IT MEANS, YOU CAN PERFORMS THE LOGICAL OR ARITHEMETICAL EXPRESSION OR OPERATION. ARITHEMETICAL SUCH AS :- + , - , * , / , % ETC. LOGICAL SUCH AS :- && , || , != , < , > , < = , > = ETC. EXAMPLE :- int s,x,y;[ Decleration] s = x + y ;[ Process] RAKESH ANAND

  27. RAKESH ANAND

  28. OUTPUT :- IT MEANS , YOU CAN SEE THE OUTPUT OF THE PROGRAM. FOR THIS WE USE printf KEYWORD. SYNTAX :- printf (“CONTROL STRING”,LIST OF VARIABLES); EXAMPLE :- int x,y,s; [DECLERATION] printf(“enter the first no:”); scanf(“%d”,&x); [INITIALIZATION] printf(“enter the second no:”); scanf(“%d”,&y); [INITIALIZATION] s = x + y; printf(“sum of two nos=%d”,s); [OUTPUT] [or printf(“%d”,s); ] [OUTPUT] CONTROL STRING STRING CONSTANT (STATEMENT) OPTIONAL ENTRY TYPE SPECIFIER (MANDATORY) RAKESH ANAND

  29. A PROGRAM TO PRINT THE SUM OF TWO NOS. THROUGH COMPILE TIME INITIALIZATION:- main( ) { int x,y,s; x = 10; y = 25 ; s = x + y; printf(“SUM OF TWO NOS.=%d”,s); } A PROGRAM TO PRINT THE SUM OF TWO NOS. THROUGH RUN TIME INITIALIZATION:- main( ) { int x,y,s; printf(“enter the 1st nos.:”); scanf(“%d”,&x); printf(“enter the 2nd nos,:”); scanf(“%d”,&y); s = x + y; printf(“SUM OF TWO NOS.=%d”,s); } A SIMPLE PROGRAM IN ‘C’ LANGUAGE :- main ( ) { printf(“this is my first program.”); printf(“Developed by RAKESH ANAND”); } RAKESH ANAND

  30. HOW TO COMPILE A PROGRAM :- FOR THIS , WE USE [Alt + c] OR [Alt + F9] OR [F9]. COMPILING IS GENERALLY USED FOR SEEING THE ERROR OF THE PROGRAM. HOW TO RUN A PROGRAM :- FOR RUNNING THE PROGRAM , WE USE [Alt + r ] or [Ctrl + F9] HOW TO SEE OR VIEW THE OUTPUT OF A PROGRAM :- FOR THIS, WE USE [Alt + F5] HOW TO SAVE A PROGRAM :- FIRSTLY, WE USE [Alt + f] AND THEN SELECT SAVE SUB MENU AND PRESS ENTER KEY AND THEN GIVING THE NAME WITH DESIRED PLACE AND THEN PRESS ENTER KEY. OR PRESS F2 AND THEN GIVING THE NAME WITH DESIRED PLACE AND THEN PRESS ENTER KEY. HOW TO CLEAR THE SCREEN :- FOR CLEARING THE SCREEN , WE USE clrscr( ); IT IS USED AFTER THE DECLERATION OF THE VARIABLE. SUCH AS :- int x,y,z; [Decleration ] clrscr( ); HOW TO GET THE FULL SCREEN :- FOR FULL SCREEN , WE USE [ Alt + enter ] KEY. HOW TO BREAK THE EXECUTION OF THE PROGRAM ON THE SCREEN :- FOR THIS , WE USE getch( ); BUT IT IS GENERALLY USED FOR INPUTTING THE VALUE OF THE VARIABLE OR SOMETHING. RAKESH ANAND

  31. Firstly press Alt + f key and then select New option for creating new ‘C’ file and then press enter key. Write the code or program in this area. RAKESH ANAND

  32. For saving the program, firstly press Alt + f key and then select the save option and then press enter key .( or press F2 function key). After perssing the enter key and it gives a box for writing the file name with desired path and then press enter key. RAKESH ANAND

  33. Firstly press Alt + c key and then press enter key for compiling the program. After pressing enter , a dialogue box appears and it shows many things and then press enter key. If any error occurs firstly correct the error(s). And then run the program. RAKESH ANAND

  34. For running the program , firstly press Alt + r key and then press enter key. After pressing enter key ,it will show and wait for inputing. RAKESH ANAND

  35. Input the required value of the variable and then press enter key. After pressing the enter key, it will show the main screen . And then press Alt + F5 key for seeing the output of the program. After pressing these key it will show the accurate ouput. RAKESH ANAND

  36. ESCAPE SEQUENCE :- \a ----------- Audible alert (Bell) \b ---------- Back space \f ---------- Form feed \r ---------- carriage return \n ----------- New line \t ----------- Horizontal Tab \v ----------- Vertical Ttab \’ ----------- Single quote \” ----------- Double quotes \? ----------- Question mark \\ ----------- Back slash \0 ----------- Null ‘ C ’ support some special backslash character constants that are used in output function. It is combination of backslash and one caharacter. These character combination are calledESCAPE SEQUENCE. HOW TO ESCAPE FROM THE ‘ C ’ COMPILER :- FOR OUTGOING FROM ‘C’ COMPILER, WE PRESS [Alt + x ] key. SOME NOTES :- COMMENTS :- ‘0’ IS USED FOR FALSE STATEMENT OR CONDITION. (-VE) ‘1’ IS USED FOR TRUE STATEMENT OR CONDITION. (+VE) IT IS USED FOR DOCUMENTATION AND YOU CAN TAKE IT ANYWHERE IN THE PROGRAM. SYNTAX :- /* --------- STATEMENT----------- */ IT DOESN’T PARTICIPATES IN THE PROGRAM EXECUTION. RAKESH ANAND

  37. RAKESH ANAND

  38. ( ? : ) SYNTAX :- (COND) ? TRUE STATEMENT : FALSE STATEMENT ; EXAMPLE :- Write a program to fine the biggest no. among two nos. Soln :- main( ) { int x,y,b; clrscr( ); Printf(“ enter the two nos. ”); Scanf(“ %d %d ”,&x , &y); b = ( x > y ) ? x : y ; printf(“Biggest no = %d ”,b); } > , < , > = , < = , = = (comparision) ,! =(not equa to) etc. multiplication • = (c = 0 ) , + = ( c = c +a or c+=a), • = (c = c – a or c-=a), • *= (c = c * a or (c*=a), • / = (c = c / a or c/=a ) , • % = (c = c % a or c%=a) etc. ‘ + ’ , ‘ – ’ , ‘ * ’ , ‘ / ’ , ‘ % ’ It is used for compound relation. && (and) , || (or ) etc. Modular (remainder) • ++ (increment ) and • - (decrement) . • (C = C + 1 OR C+=1 OR ++C) • AND • (C = C – 1 OR C-=1 OR --C) RAKESH ANAND

  39. OPERATOR PRECEDENCE AND ASSOCIATIVITY :- OPERATOR DESCRIPTION ASSOCIATIVITY RANK -------------------------------------------------------------------------------------------------------- ( ) Function call Left to Right 1 [ ] Array element reference -------------------------------------------------------------------------------------------------------- + Unary plus - Unary minus + + Increment - - Decrement ! Logical negation Right to left 2 ~ One’s complement * Pointer reference & Address sizeof Size of an object (type) Type cast (conversion) -------------------------------------------------------------------------------------------------------- * Multiplication / Division Left to right 3 % Modulus -------------------------------------------------------------------------------------------------------- RAKESH ANAND

  40. OPERATOR PRECEDENCE AND ASSOCIATIVITY :- OPERATOR DESCRIPTION ASSOCIATIVITY RANK -------------------------------------------------------------------------------------------------------- + Addition Left to Right 4 - Substraction -------------------------------------------------------------------------------------------------------- << Left shift Left to right 5 >> Right shift -------------------------------------------------------------------------------------------------------- < Less than Left to right 6 < = Less than or equal to > Greater than > = Greater than or equal to -------------------------------------------------------------------------------------------------------- = = Equality Left to right 7 ! = Inequality --------------------------------------------------------------------------------------------------------- & Bitwise AND Left to right 8 --------------------------------------------------------------------------------------------------------- ^ Bitwise XOR Left to right 9 --------------------------------------------------------------------------------------------------------- RAKESH ANAND

  41. OPERATOR PRECEDENCE AND ASSOCIATIVITY :- OPERATOR DESCRIPTION ASSOCIATIVITY RANK -------------------------------------------------------------------------------------------------------- | Bitwise OR Left to Right 10 -------------------------------------------------------------------------------------------------------- && Logical AND Left to right 11 -------------------------------------------------------------------------------------------------------- || Logical OR Left to right 12 -------------------------------------------------------------------------------------------------------- ? : Condition expression Right to left 13 ------------------------------------------------------------------------------------------------------- = Assignment operators Right to left 14 * = , / = , % = + = , - =, & = ^ = , | = << = , >> = --------------------------------------------------------------------------------------------------------- , Comma operator Left to right 15 RAKESH ANAND

  42. RAKESH ANAND

  43. s = x + y ; p = x * y; r = n % 2; Etc. SUM : s = x + y ; p = x * y ; For this purpose, we use goto keyword. It will be discussed in next slide. It is a label name. RAKESH ANAND

  44. IT IS USED FOR JUMPING THE STATEMENT FOR ONE PLACE TO DESIRED PLACE . FOR THIS , WE USE GOTO,BREAK AND CONTINUE STATEMENT. IT IS USED FOR REPEATING( OR MAKING LOOP) THE SAME STATEMENT OR PROCESS. FOR THIS , WE USE DO – WHILE , WHILE AND FOR LOOP. IT IS USED FOR MAKING SINGLE OR MULTIPLE DECISION. IN TRUE OR FALSE CONDITION. FOR THIS , WE USE CONDITIONAL OPERATOR OR IF – ELSE STATEMENT. RAKESH ANAND

  45. DIAGRAM : - START PROCESS 1 NO (FALSE) YES (TRUE) CONDITION PROCESS 2 PROCESS 3 PROCESS 4 END RAKESH ANAND

  46. EXAMPLE ON SELECTION STATEMENT (BRANCHING) int x ,y, s , p ; y N x > y s = x + y; p = x * y ; Print result RAKESH ANAND

  47. DIAGRAM :- START PROCESS 1 Y COND PROCESS 2 N PROCESS 3 PROCESS 4 PROCESS 5 RAKESH ANAND

  48. DIAGRAM :- START PROCESS 1 PROCESS 2 Y COND PROCESS 3 N END PROCESS 4 RAKESH ANAND

  49. RAKESH ANAND

  50. HOW TO MAKE A SELECTION :- 1. USING TERNARY OPERATOR OR CONDITION OPERATOR 2. USING “ IF STATEMENT ” “ if ” is a keyword which makes a selection. RAKESH ANAND

More Related