+ All Categories
Home > Software > Questions typedef and macros

Questions typedef and macros

Date post: 13-Jan-2017
Category:
Upload: mohammed-sikander
View: 70 times
Download: 0 times
Share this document with a friend
21
Transcript
Page 1: Questions typedef and macros
Page 2: Questions typedef and macros

Primitive Syntax : typedef existing-type new-name ;

Examples:

Page 3: Questions typedef and macros
Page 4: Questions typedef and macros

Is this correct / valid?

How do I type define an String

Page 5: Questions typedef and macros
Page 6: Questions typedef and macros
Page 7: Questions typedef and macros
Page 8: Questions typedef and macros
Page 9: Questions typedef and macros
Page 10: Questions typedef and macros

In the above declaration, SavingsAccount is an Variable or Typedefinition?.

Page 11: Questions typedef and macros
Page 12: Questions typedef and macros

P1 is pointer to constP2 is constant

pointerP3 is constant

pointerP4 is constant

pointer

Page 13: Questions typedef and macros

int main( ){

#define PI 3.14int r = 3;float area = PI * r * r;printf(" %f",area);

}

Page 14: Questions typedef and macros

void calculateArea( );int main( ){

#define PI 3.14 calculateArea( );

}

void calculateArea( ){

int r = 3;float area = PI * r * r;printf(" %f",area);

}

Page 15: Questions typedef and macros

void calculateArea( );int main( ){

#define PI 3.14int r = 3;float area = PI * r * r;printf(" %f",area); calculateArea( );

}

void calculateArea( ){

int r = 3;float area = PI * r * r;printf(" %f",area);

}

Page 16: Questions typedef and macros

void calculateArea( );int main( ){

#define PI 3.14int r = 3;float area = PI * r * r;printf(" %f",area);#undef PI calculateArea( );

}void calculateArea( ){

int r = 3;float area = PI * r * r;printf(" %f",area);

}

void calculateArea( );int main( ){

#define PI 3.14int r = 3;float area = PI * r * r;printf(" %f",area); calculateArea( );#undef PI

}void calculateArea( ){

int r = 3;float area = PI * r * r;printf(" %f",area);

}

Page 17: Questions typedef and macros

1. int main( )2. {3. int a = 5;4. if( a )5. printf(“if

executed");

6. #if (a)7. printf("#if

executed");8. #endif9. }

a) Compilation Error in Line 6

b) Both printf are executedc) Only the first pf is

executed

Page 18: Questions typedef and macros

1. #define a 02. int main( )3. {4. if( a )5. {6. #ifdef a7. printf(“A")8. #endif9. }10. }

a) No Error, No Outputb) Error in printf - ; missing

1. #define a 02. int main( )3. {4. if( a )5. {6. #if a7.

printf(“A")8. #endif9. }10. }

Page 19: Questions typedef and macros
Page 20: Questions typedef and macros

#define MAYUR 0int main( ){

#if MAYURprintf("#if executed");

#endif#ifdef MAYUR

printf("#ifdef executed");#endif

}

Page 21: Questions typedef and macros

int main( ){

#ifdef MAYURprintf("#ifdef executed");

#endif}

gcc file.c -DMAYUR


Recommended