DIPTA SAHA Diptasaha.lpu.cse@gmail.com
History Of C is a middle level programming language.which is developed by Dennis Ritchie while working at AT&T Bell Labs in USA in between 1969 and 1973.
{ First C Program; }  1#include<stdio.h>  2 int main()  3 {  4 printf("Hello C");  5 return 0;  6 }
{ Comments in C Program; } Single Line comment /*…comments…..*/ Multi Line Comments /* Comments */
{ Variable in C; }
{ Local Variable in C; } A local variable is a variable that is declared inside a function.
{ Global Variable in C; } A Global variable is a variable that is declared Outsite a function.
{ Data type in C; }
{ Size of Data type in C; } int 2 -32768 to +32767 long 4 -2,147,483,648 to 2,147,483,647 Float 4 1.2E-38 to 3.4E+38 Double 8 2.3E-308 to 1.7E+308 Char 1 -128 to +127 Data Type Name Size(Byte) Range
{ Variable Declaration in C; }  Syntax Datatype_name variable_name; or Datatype_name variable_name = values; Example Int a; Or Int a = 100;
{ Constant Variable Declaration in C; }  Syntax Const Datatype_name variable_name = values; Example Const float pi = 3.1416;
{ Format Specifier in C; }
{ Escape Sequence in C; } •n (newline) •t (tab) •v (vertical tab) •f (new page) •b (backspace) •r (carriage return) •n (newline)
{ get From User in C; }  Syntax scanf("%d",&i); Example Int a; Scanf(“%d”,&a);
{ Simple Program for get From User in C; }
{ Operator in C; } C language is rich in built-in operators and provides the following types of operators − 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Bitwise Operators 5. Assignment Operator
{ Arithmetic Operator in C; }
{ Relational Operator in C; }
{ Logical Operator in C; }
{ Bitwise Operator in C; }
{ Assingment Operator in C; }
{ Condition Operator in C; } Syntax: (condition) ? True_res : false_res; #include <stdio.h> int main() { int x=1, y ; y = ( x ==1 ? 2 : 0 ) ; printf("x value is %dn", x); printf("y value is %d", y); }
{ Simple Program Using Operator in C; }  1 #include<stdio.h>  2int main()  3{  4 int a=10,b=5;  5 int add = a+b;  6 int sub = a-b;  7 int mul = a*b;  8 int div = a/b;  9 printf(“Add = %d”,add);  10 printf(“Sub = %d”,sub);  11 printf(“mul = %d”,mul);  12. printf(“div = %d”,div);  13return 0;  14}
{ Decision making in C; }
{ Conditional Execution in C; } In the c programming have some decision making Statement. 1. if statement 2. if...else statement 3. nested if statements 4.switch statement 5. nested switch statements
{ If Condition in C; }  Syntax If(condition) { Statement..1; Statement..2; Statement..n; }
{ Simple Program using If Condition in C; }
{ if else Condition in C; }  Syntax If(condition) { Statement; } Else { Statement; }
{ Simple Program using If else Condition in C; }
{ Nested if Condition in C; }  Syntax If(condition) { Statement; if(condition) { Statement; } }
{ Switch Statement in C; }  Syntax Switch(expression) { Case constant_expression_1: Statement 1; Break; Case constant_expression_2: Statement 2; Break; Case constant_expression_3: Statement 3; Break; Default: Statement 4; }
{ nested Switch Statement in C; }  Syntax Switch(expression-1) { Case constant_expression_1: Switch(expression-1) { case constant_expression : statement; break; } Break; Case constant_expression_2: Statement 2; Break; Default: Statement 3; }
{ Loops in C; }
{ Types of Loops in C; } 1. while loop 2. for loop 3. do...while loop 4. nested loops
{ while Loop in C; } Syntax Initialization; While(condition) { Statement..1; Statement..2; Statement..n; increment/decrement; }
{ A simple Program using While Loop in C; }
{ for Loop in C; } Syntax for(Initialization;condition; increment/decrement) { Statement..1; Statement..2; Statement..n; }
{ A simple Program using For Loop in C; }
{ do while Loop in C; } Syntax Initialization; do { Statement..1; Statement..2; Statement..n; increment/decrement; } While(condition)
{ A simple Program using Do While Loop in C; }
{ nested for Loop in C; } Syntax for(Initialization;condition; increment/decrement) { Statement..1; for(Initialization;condition; increment/decrement) { Statement..1; Statement..2; Statement..n; } }
{ Break Statement in C; } The break statement terminates the loop body immediately and passes control to the next statement after the loop. Break statement are mainly used with loop and switch statement.
{ A Simple Program Using Break Statement in C; }
{ Continue Statement in C; } The continue statement in C programming works somewhat like the breakstatement.
{ A Simple Program Using continue Statement in C; }
{ Function in C; } Syntax Return_type function_name(argument) { statement; return need_variable; } Example: Int sum(int x,int y) { return x+y; }
{ Function call in C; } Syntax: Function_name(parameter or argument); Example: 1 #include<stdio.h> 2 int main() 3 { 4 Int z=sum(10,20); 5 printf(z); 6 return 0; 7 }
{ Array in C; }
{ Types Of Array in C; }
{ Single Dimensional Array in C; } Syntax data_type array_name [size];
{ Multi Dimensional Array in C; } Syntax data_type array_name [row_size][column_size];
{ A simple program using 1D Array in C; }
{ * Pointer in C; } A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before using it to store any variable address.
{ Declaration of Pointer in C; } Syntax data_type *var_name; Example int var = 20; int *ip; ip = &var;
{ A Simple Program Using Pointer in C; }
{ File in C; } file is a place on your physical disk where information is stored. Open a File FILE *name; name = fopen(“text.txt","a"); fclose(name);
{ File in C; } Write in a File FILE *name; name = fopen(“text.txt",“w"); If(name == NULL) { printf(“File Dose Not exist”); } else { for(i = 0; i < 10;i++){ fprintf (fp, "This is line %dn",i + 1); } fclose(name); }
{ File in C; } Read in a File FILE *name; name = fopen(“text.txt",“w"); Char buff[200]; If(name == NULL) { printf(“File Dose Not exist”); } else { while(fscanf(fp, "%s", buff)!=EOF){ printf("%s ", buff ); } fclose(name); }
exit(Presentation);

Programming in C Presentation upto FILE

  • 1.
  • 2.
    History Of C isa middle level programming language.which is developed by Dennis Ritchie while working at AT&T Bell Labs in USA in between 1969 and 1973.
  • 3.
    { First C Program; } 1#include<stdio.h>  2 int main()  3 {  4 printf("Hello C");  5 return 0;  6 }
  • 4.
    { Comments in CProgram; } Single Line comment /*…comments…..*/ Multi Line Comments /* Comments */
  • 5.
  • 6.
    { Local Variable inC; } A local variable is a variable that is declared inside a function.
  • 7.
    { Global Variable inC; } A Global variable is a variable that is declared Outsite a function.
  • 8.
  • 9.
    { Size of Datatype in C; } int 2 -32768 to +32767 long 4 -2,147,483,648 to 2,147,483,647 Float 4 1.2E-38 to 3.4E+38 Double 8 2.3E-308 to 1.7E+308 Char 1 -128 to +127 Data Type Name Size(Byte) Range
  • 10.
    { Variable Declaration inC; }  Syntax Datatype_name variable_name; or Datatype_name variable_name = values; Example Int a; Or Int a = 100;
  • 11.
    { Constant Variable Declarationin C; }  Syntax Const Datatype_name variable_name = values; Example Const float pi = 3.1416;
  • 12.
  • 13.
    { Escape Sequence inC; } •n (newline) •t (tab) •v (vertical tab) •f (new page) •b (backspace) •r (carriage return) •n (newline)
  • 14.
    { get From Userin C; }  Syntax scanf("%d",&i); Example Int a; Scanf(“%d”,&a);
  • 15.
    { Simple Program forget From User in C; }
  • 16.
    { Operator in C; } Clanguage is rich in built-in operators and provides the following types of operators − 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Bitwise Operators 5. Assignment Operator
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
    { Condition Operator inC; } Syntax: (condition) ? True_res : false_res; #include <stdio.h> int main() { int x=1, y ; y = ( x ==1 ? 2 : 0 ) ; printf("x value is %dn", x); printf("y value is %d", y); }
  • 23.
    { Simple Program UsingOperator in C; }  1 #include<stdio.h>  2int main()  3{  4 int a=10,b=5;  5 int add = a+b;  6 int sub = a-b;  7 int mul = a*b;  8 int div = a/b;  9 printf(“Add = %d”,add);  10 printf(“Sub = %d”,sub);  11 printf(“mul = %d”,mul);  12. printf(“div = %d”,div);  13return 0;  14}
  • 24.
  • 25.
    { Conditional Execution inC; } In the c programming have some decision making Statement. 1. if statement 2. if...else statement 3. nested if statements 4.switch statement 5. nested switch statements
  • 26.
    { If Condition inC; }  Syntax If(condition) { Statement..1; Statement..2; Statement..n; }
  • 27.
    { Simple Program usingIf Condition in C; }
  • 28.
    { if else Conditionin C; }  Syntax If(condition) { Statement; } Else { Statement; }
  • 29.
    { Simple Program usingIf else Condition in C; }
  • 30.
    { Nested if Conditionin C; }  Syntax If(condition) { Statement; if(condition) { Statement; } }
  • 31.
    { Switch Statement inC; }  Syntax Switch(expression) { Case constant_expression_1: Statement 1; Break; Case constant_expression_2: Statement 2; Break; Case constant_expression_3: Statement 3; Break; Default: Statement 4; }
  • 32.
    { nested Switch Statementin C; }  Syntax Switch(expression-1) { Case constant_expression_1: Switch(expression-1) { case constant_expression : statement; break; } Break; Case constant_expression_2: Statement 2; Break; Default: Statement 3; }
  • 33.
  • 34.
    { Types of Loopsin C; } 1. while loop 2. for loop 3. do...while loop 4. nested loops
  • 35.
    { while Loop inC; } Syntax Initialization; While(condition) { Statement..1; Statement..2; Statement..n; increment/decrement; }
  • 36.
    { A simple Programusing While Loop in C; }
  • 37.
    { for Loop inC; } Syntax for(Initialization;condition; increment/decrement) { Statement..1; Statement..2; Statement..n; }
  • 38.
    { A simple Programusing For Loop in C; }
  • 39.
    { do while Loopin C; } Syntax Initialization; do { Statement..1; Statement..2; Statement..n; increment/decrement; } While(condition)
  • 40.
    { A simple Programusing Do While Loop in C; }
  • 41.
    { nested for Loopin C; } Syntax for(Initialization;condition; increment/decrement) { Statement..1; for(Initialization;condition; increment/decrement) { Statement..1; Statement..2; Statement..n; } }
  • 42.
    { Break Statement inC; } The break statement terminates the loop body immediately and passes control to the next statement after the loop. Break statement are mainly used with loop and switch statement.
  • 43.
    { A Simple ProgramUsing Break Statement in C; }
  • 44.
    { Continue Statement inC; } The continue statement in C programming works somewhat like the breakstatement.
  • 45.
    { A Simple ProgramUsing continue Statement in C; }
  • 46.
    { Function in C; }Syntax Return_type function_name(argument) { statement; return need_variable; } Example: Int sum(int x,int y) { return x+y; }
  • 47.
    { Function call inC; } Syntax: Function_name(parameter or argument); Example: 1 #include<stdio.h> 2 int main() 3 { 4 Int z=sum(10,20); 5 printf(z); 6 return 0; 7 }
  • 48.
  • 49.
  • 50.
    { Single Dimensional Arrayin C; } Syntax data_type array_name [size];
  • 51.
    { Multi Dimensional Arrayin C; } Syntax data_type array_name [row_size][column_size];
  • 52.
    { A simple programusing 1D Array in C; }
  • 53.
    { * Pointer inC; } A pointer is a variable whose value is the address of another variable. Like any variable or constant, you must declare a pointer before using it to store any variable address.
  • 54.
    { Declaration of Pointerin C; } Syntax data_type *var_name; Example int var = 20; int *ip; ip = &var;
  • 55.
    { A Simple ProgramUsing Pointer in C; }
  • 56.
    { File in C; } fileis a place on your physical disk where information is stored. Open a File FILE *name; name = fopen(“text.txt","a"); fclose(name);
  • 57.
    { File in C; } Writein a File FILE *name; name = fopen(“text.txt",“w"); If(name == NULL) { printf(“File Dose Not exist”); } else { for(i = 0; i < 10;i++){ fprintf (fp, "This is line %dn",i + 1); } fclose(name); }
  • 58.
    { File in C; } Readin a File FILE *name; name = fopen(“text.txt",“w"); Char buff[200]; If(name == NULL) { printf(“File Dose Not exist”); } else { while(fscanf(fp, "%s", buff)!=EOF){ printf("%s ", buff ); } fclose(name); }
  • 59.