Basics of C porgramming


Published on

Basics of C porgramming

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Basics of C porgramming

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Basics of C Program Niyaz Kannanchery tweetboy niyazsky 9746 049 048 in/niyazsky
  3. 3. Info about C C is a general-purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. It was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972. The Unix operating system and virtually all Unix applications are written in the C language. C has now become a widely used professional language for various reasons. • Easy to learn • Structured language • It produces efficient programs. • It can handle low-level activities. • It can be compiled on a variety of computers
  4. 4. Facts about C Language • C was invented to write an operating system called UNIX. • C is a successor of B language which was introduced around 1970 • The language was formalized in 1988 by the American National Standard Institue (ANSI). • By 1973 UNIX OS almost totally written in C. • Today C is the most widely used System Programming Language. • Most of the state of the art software have been implemented using C Note the followings  C is a case sensitive programming language. It means in C printf and Printf will have different meanings.  C has a free-form line structure. End of each C statement must be marked with a semicolon.  Multiple statements can be one the same line.  White Spaces (ie tab space and space bar ) are ignored.  Statements can continue over multiple lines.
  5. 5. KeyWords Constants Strings Identifers Special Symbols Operators In a C source program, the basic element recognized by the compiler is the "token." A token is source-program text that the compiler does not break down into component elements.
  6. 6. Sample C Program Code #include<stdio.h> void main() { int A,B,C; printf("Enter the two numbern"); scanf("%d %d",&A,&B); C=A+B; printf("%dn",C); }
  7. 7. Keywords are the base building block of any Computer Language. Keywords tells to the compiler of the Language what Programmer meant. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while
  8. 8. Identifiers The name of Variable,Functions,Labels and various other user defined items are Called identifier. The length of these identifier can vary from one to several character. Rules for Identifiers  First character must be in alphabet or underscore.  Must consist of only letters, digits or underscore.  Only first 31 character are significant.  Cannot use a Keyword.  Must not contain white Space
  9. 9. Constants Its an Variable that says the same once declared and cannot be change at run time. String A string is a Sequence of Character enclosed in double quotes. Operators An Operators is a symbol that tells the computer to Perform certain mathematical or Logical operations. Special Symbols Space + - * / ^ () [] {} = != <> ‘ “ $ , ; : % ! & ? _ # <= >= @
  10. 10. DATA TYPES in C Language C has a concept of 'data types' which are used to define a variable before its use. The definition of a variable will assign storage for the variable and define the type of data that will be held in the location. The value of a variable can be changed any time. C has the following basic built-in datatypes  int  float  double  char
  11. 11. Format Specifiers Format Specifiers There are many format specifiers defined in C. Take a look at the following list Format Specifiers Using for %i or %d int %c Char %f Float %lf Double %s String
  12. 12. Sample C Program Code #include<stdio.h> void main() { int A,B,C; printf("Enter the two numbern"); scanf("%d %d",&A,&B); C=A+B; printf("%dn",C); }
  13. 13. Understanding the Execution
  14. 14. Decision Making Statements Statement Description if statement An if statement consists of a boolean expression followed by one or more statements. if...else statement An if statement can be followed by an optional else statement, which executes when the boolean expression is false. nested if statements You can use one if or else if statement inside another if or else if statement(s). switch statement A switch statement allows a variable to be tested for equality against a list of values. nested switch statements You can use one swicth statement inside another switchstatement(s).
  15. 15. Problem Statement If Statement Enter a number & Check whether its Less than 100?
  16. 16. If Statement #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* check the boolean condition using if statement */ if( a < 20 ) { /* if condition is true then print the following */ printf("a is less than 20n" ); } printf("value of a is : %dn", a); return 0; }
  17. 17. Problem Statement If Else Statement Find a Person can do Vote in Election? based on Age.
  18. 18. If else statement #include <stdio.h> int main () { /* local variable definition */ int a = 100; /* check the boolean condition */ if( a < 20 ) { /* if condition is true then print the following */ printf("a is less than 20n" ); } else { /* if condition is false then print the following */ printf("a is not less than 20n" ); } printf("value of a is : %dn", a); return 0; }
  19. 19. Problem Statement Switch Statement Selecting new language in Mobile?
  20. 20. Switch Statement #include <stdio.h> int main () { /* local variable definition */ char grade = 'B'; switch(grade) { case 'A' : printf("Excellent!n" ); break; case 'B' : printf("Well donen" ); break; case 'D' : printf("You passedn" ); break; case 'F' : printf("Better try againn" ); break; default : printf("Invalid graden" ); } printf("Your grade is %cn", grade ); return 0; }
  21. 21. Loops Loop Type Description while loop Repeats a statement or group of statements until a given condition is true. It tests the condition before executing the loop body.( First Check the Condition, If its true enter the Loop) for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable (initialization, Condition, Increment or decrement) do...while loop Like a while statement, except that it tests the condition at the end of the loop body. (Whatever the condition it execute at least once) nested loops You can use one or more loop inside any another while, for or do..while loop (inside another loop)
  22. 22. Problem Statement For Loop Enter and Display Student is Elite or Normal? Based on Fee
  23. 23. For Loop #include <stdio.h> int main () { /* for loop execution */ for( int a = 10; a < 20; a = a + 1 ) { printf("value of a: %dn", a); } return 0; }
  24. 24. While Loop #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %dn", a); a++; } return 0; }
  25. 25. Array An array is data structure (type of memory layout) that stores a collection of individual values that are of the same data type.
  26. 26. Problem Statement Array Enter Roll No and Mark of Students and Display it? (0) 10001 56 (1) (1) 10002 46 (2) (2) 10003 67 (3) (3) 10004 47 (4) Click for Program
  28. 28. If this presentation helped you, please visit our page and like it. Thanks in advance. | |