0

How p4 is giving output 1 in this code can anyone explain this to me ?

#include<stdio.h> #define cp_d char* typedef char* cp_t; int main(){ cp_t p1,p2; cp_d p3,p4; printf("%d %d\n",sizeof(p1),sizeof(p2)); printf("%d %d\n",sizeof(p3),sizeof(p4)); return 0; }

12th Aug 2020, 8:50 AM
Ayush Singh..
Ayush Singh.. - avatar
1 Antwort
+ 1
Because `cp_d` in main function is replaced by `char*` before the compilation. The line 👇 cp_d p3, p4; Will be replaced by 👇before compilation char* p3, p4; which means, <p3> is a pointer, but <p4> is plain char (not a pointer). In case of `cp_t`, both <p1> and <p2> are both defined as `char*` because `typedef` defined a type alias.
12th Aug 2020, 10:41 AM
Ipang