Posts

Showing posts from September, 2020

Void pointer in c

 //Void pointer used to store value of other variables  y z etc in one another variable x etc #include <stdio.h> int main() { void *v;    // int *p , *q;     int x =10 , y;     float avg = 12.12;     char k = 'A';          v = &x;     y = *((int *)v);     printf("y=%d\n" , y);          v=&k;     printf("y = %c\n" , *(char *)v);          v = &avg;     printf("y= %f\n", *((float *)v));                    return 0; }

Pointer initialising

 #include <stdio.h> int main() {     int x=10;      int *p = 0;     p = &x;     if ( p != 0){         *p = 100;         printf("%u is the memory address  of x\n %d is the  value at *p(x)\n %d is the alter value of x", p,*p , x);              }else{         printf("ERROR");     }     return 0; }

Pointer Arithmetic in c

//after1000 their is no 1001 bcoz size of integer is 4byte  #include <stdio.h> int main() {      int *p;     p = 1000;        *p++;   printf("size of integer  %d\n bytes of operator\n" , sizeof(int) );   printf("size of character is %d bytes of operator\n", sizeof(char));     printf("%d", p);     return 0; }

Stringizing Operator and Pasting Operator

 //stringizing operator : in this operater we doesnot use double code in printf""" #include <stdio.h> #define NAME(s) #s int main() {          printf( NAME(rohit parmar) );     return 0; } // pasting operator : // this operator we use ## and it concat(add) the terms #include <stdio.h> #define CONCAT(a,b) a ## b int main() {     int xy = 23;     int pq = 20;     printf( "%d\n" , CONCAT(x,y) );     printf ("%d\n", CONCAT(p,q));     return 0; }

Some more Pre define macros

#include <stdio.h> int main() {         printf(" %s\n" , __FILE__);     printf(" %d\n" , __LINE__);     printf(" %d\n" , __func__);     printf(" %s\n" , __DATE__);     printf(" %s\n" , __TIME__);     return 0; }

#ifdef #ifndef #unfef

 1 #ifdef #ifdef use and excusion in c 👇👇👇👇👇👇👇👇 //ifdef stand for "if define" and ifndef stand for "if not define" // ifndef is just opposite of ifdef #include <stdio.h> #define INTEL int main() {     #ifdef INTEL printf("jo bhi statement ifdef and endif \ ke bich me he wo exculte ho ga"); #endif          return 0; } 2 #ifndef  #ifndef use and excusion in c 👇👇👇👇👇👇👇👇👇 //if we remove comments than #else statement excuted // but here #ifndef statement excute only #include <stdio.h> int main() //#define INTEL {     #ifndef INTEL      printf("jo bhi statement ifndef and endif ke bich me he wo exculte ho ga"); //#else //printf(" above statement not excuted "); #endif          return 0; } 3 #undef #undef use and excution in c 👇👇👇👇👇👇👇👇 //#undef stand for undefine it means the macro is not define or undefine #include <stdio.h> int main() #define INTEL {  ...

Conditional Compilation #if #elif #endif

 //**conditional compilation** //we use # before if because it is a macro defination program  //and we use #endif to end the #if statement  //their is no need of pare of parenthesis in if statement bcoz it work on macro #include <stdio.h> #include <stdlib.h> #define INDIA 1  #define PAKISTAN 2 #define USA 3  #define ISRAIL 4 #define COUNTRY INDIA #define AGE 19 int main() {      printf("code for the universe\n"); #if COUNTRY == INDIA printf("code for the indians\n"); #if AGE >= 18 printf("you are eligible for this code\n"); #endif  #elif COUNTRY == USA printf("code for the USA\n"); #if AGE >= 18 printf("you are eligible for this code\n"); #endif #elif COUNTRY == PAK printf("code for the pak\n"); #if AGE >= 18 printf("you are eligible for this code\n"); #endif #else  printf(" code for other country except india usa and pak\n"); #endif      return 0; }

Function like macros

 #include <stdio.h> #define ONE 1 #define AND && #define OR || #define TWO ONE + ONE #define THREE TWO + ONE #define MESSAGE "we can extend \  the macro template by\  using back slash" int main() {     if (1 AND 1){printf("something true\n");}     printf("%d\n", TWO);;     printf("%d\n", THREE);    printf( MESSAGE);          return 0; } *********************************** #include <stdio.h> #include <stdlib.h>  #define SQUARE(X,Y) X*Y int main() {int result = SQUARE (10, 12); printf("%d \n" , result);     return 0; }

#define : pre prosesor directive

 //Here in the program define is called defination and // LIMIT is called macro template and 5 is called macro expansion //The we use capital letter in macro template // and we never use semi colomn in macro defination #include <stdio.h> #define LIMIT 5 #define PI 3.1472 #define DISPLAY printf("HELLO WORLD\n"); #define PASSWORD "18158920@abc" int main() { int counter ; for(counter =1;counter<=LIMIT; counter++)     printf("%d\n", counter);     printf("%f is the value of PI\n ", PI);     DISPLAY     printf("Password is %s\n" , PASSWORD);     return 0; }

Pass by reference...

 #include <stdio.h> void display( int *); int main() { int num = 10;     printf("num = %d\n", num);     printf("memory location of num variable is %u\n", &num); display(&num); printf("now i am completed pass by refrence too\n");     return 0; } void display(int *pointer){      ;     printf(" value at pointer variable is  %d\n", *pointer);     printf("memory address of pointer is %u\n", &pointer);           *pointer = 20;     printf("memory address of pointer is %u\n", *pointer); }

Pointer to another pointer

 //*P and **q denote a new one memory location.... #include <stdio.h> int main() {     int i =10;     int  *p,**q;      p = & i;      q = & p;                    printf ("real value of i is %d\n",i );    printf("memory address of i is %u\n",&i);         printf(" memory address of i stored in p is %u\n",p );    printf("memory address of p is %u\n",&p);    printf("memory address of p stored in q is %u\n", q);     printf("memory address of k is %u\n",&q);          printf("\n\n");          printf("%d\n", *p);    printf("%u\n", *q);    printf("%u\n", **q);                  return 0; }

pointer : Introduction

 #include <stdio.h> int main() {      int a = 12;     int *P;      int p = &a;     printf(" Real value of a= %d\n" , a);     printf(" memory location of a= %u\n" , &a);     printf(" value of memory address of a= %u\n" , *(&a));     printf(" memory  location of p= %u\n" , &p);     printf(" value of memory address  of p= %u\n" , *(&a));    // printf(" value of memory address  of p= %u\n" , *p);     return 0; }

Memory address and Value at in c

memory address : we use '&' symbol    , and  in value at memory address: we use '*' symbol #include <stdio.h> int main() {      int a = 12;          printf("memory address of a is %u\n" , &a);     printf("value  at memory address of a  %u is %d\n" , &a , *(&a));     return 0; }

Global variable in c

 global variable👇                                                                                                                                                                                #include <stdio.h> // you can write below statement if you want it doesnot effect the program ///void display (); int a, b; int main() {     a=12;     b=13; display ();     return 0; } void display (){         printf("sum of %d and %d is %d\n " , a,b,(a+b));     //or    //pri...

one dimensional array function

 #include <stdio.h> #include<stdlib.h> void displaysinglename(char []); int main() {     char names[][20] = {         "Rohit",         "sumit",         "ashish",         "Bhanu"              };            displaysinglename(names[2]);     return 0; }            void displaysinglename(char singlename[]){          printf("%s\n", singlename);                                          }

What is function in c

  #include <stdio.h> void ad(int num1, int num2); int main() {     add(44,55);     return 0; } void add ( int num1, int num2){  int result= num1 +num2;  printf("result of %d +%d = %d", num1,num2 ,result); } //******************************** Array to function 👇 #include <stdio.h> void displaysinglemarks (int); int main() {int marks [] = {97,98,83,95,90};    displaysinglemarks (marks [4]);     return 0; } void displaysinglemarks (int marks) {  printf ("-------------display single marks----------------\n");   printf("%d", marks); } //*************************

what is format specifiar %s

 if we want to print whole strings value in one time then we directly use %s in printf #include <stdio.h> int main() { int index = 0;     //char name[] = {'r','o','h','i','t','\0'};     //char surname [] = {'p','a','r','m','a','r', '\0'};  // you can choose upper 2 lines or below 2 lines but comment any two lines        char name [] = "rohit";     char surname [] = "parmar";        printf("%s\n", name);    while ( name[index]!='\0'){        printf("%c", name[index]);        index++; }                index =0;     while ( surname[index]!='\0'){        printf("%c", surname[index]);        index++; }      return 0; }

what is string or character array

 #include <stdio.h> int main() { int index = 0;     char name[] = {'r','o','h','i','t','\0'};        while ( name[index]!='\0'){        printf("%c", name[index]);        index++;            }          return 0; } ************************  what is strings or character array in c  2 character array       given below  #include <stdio.h> int main() { int index = 0;     //char name[] = {'r','o','h','i','t','\0'};     //char surname [] = {'p','a','r','m','a','r', '\0'};  // you can choose upper 2 lines or below 2 lines but comment any two lines        char name [] = "rohit";     char surname [] = "parmar";        while ( name[index]!='\0'){        printf("%c", name[index]);        index++; }     ...

What is Array ...

 #include <stdio.h> int main() { int marks [] ={10,20,30,40,50,60,70,80,90,};     printf("%d\n", marks[6]);     return 0; } 2D Array....👇 #include <stdio.h> int main() { //int marks1[]= {97,98,83,95,90};  //int marks2[]= {92,97,92,95,76};  //int marks3[]= {80,82,83,90,60};    int marks[3][5] = {       { 97,98,83,95,90},      {92,97,92,95,76},      {80,82,83,90,60}        };     printf("%d", marks[2] [3]);     return 0; }

Switch , case statement

//This is the basic switch case statement..  #include <stdio.h> int main() { char grade ; printf("Enter your grade\n"); scanf("%c", & grade); switch(grade){     case'a':     printf("you got  the grade A\n All the best\n");     break;     case'b':     printf("you got the grade B\n All the best\n");     break;          default:     printf("unknown grade entered\n"); } //Using range in case value  #include <stdio.h> int main() { int i ; printf("Enter your marks  Obtain in class test of 15 marks \n"); scanf("%d", & i); switch(i){     case 1 :      case 2 :     case 3 :     case 4 :     case 5 :     case 6 :     case 7 :     case 8 :     case 9 :     case 10 :     printf("work hard \n All the best\n");     break;     case 11: ...