Posts

Showing posts from July, 2023

NULL Pointer in C.

  #include <stdio.h> #include <conio.h> int main () {     int b = 34 ;     int * pt = & b ;     printf ( "The address of b is %d \n " , pt );         int a = 34 ;     int * ptr = NULL ;     if ( ptr != NULL )     printf ( "The address of a is %d \n " , * ptr );     else {         printf ( "The pointer is a null pointer and can not be defrenced" );     }     return 0 ; } OUTPUT: The address of b is 6422288 The pointer is a null pointer and can not be defrenced

Void Pointer in C.

  #include <stdio.h> #include <conio.h> int main () {     int a = 345 ;     float b = 6.9 ;     void * ptr ;     ptr = & b ;     printf ( "The value of b is %f \n " , *(( float *) ptr ));     ptr = & a ;     printf ( "The value of a is %d \n " , *(( int *) ptr ));     return 0 ; } OUTPUT: The value of b is 6.900000 The value of a is 345

Storage Classes in C: Static, Extern, Auto and register.

  #include <stdio.h> // int sum = 897; // int sum = 0; int myfunc ( int a , int b ) {     // int sum;     static int myVar ;     myVar ++;     printf ( "The myVar is %d \n " , myVar );     // sum = a + b;     return myVar ; } //  int myVar = 898; int main () {     int myVar = myfunc ( 3 , 5 );     myVar = myfunc ( 3 , 5 );     myVar = myfunc ( 3 , 5 );     myVar = myfunc ( 3 , 5 );     myVar = myfunc ( 3 , 5 );     myVar = myfunc ( 3 , 5 );         return 0 ; } OUTPUT: The myVar is 1 The myVar is 2 The myVar is 3 The myVar is 4 The myVar is 5 The myVar is 6