C Programming - Typedef - Discussion
|
|
|
|
Read more:"Nothing in life is to be feared, it is only to be understood."
- Marie Curie
|
| 2. |
Is there any difference in the #define and typedef in the following code?
typedef char * string_t;
#define string_d char *;
string_t s1, s2;
string_d s3, s4;
|
Answer: Option D
Explanation:
In these declarations, s1, s2 and s3 are all treated as char*, but s4 is treated as a char, which is probably not the intention.
|
|
Palani said:
(Sat, Dec 4, 2010 05:12:37 AM)
|
|
| |
| Please explain anyone properly |
|
Sundar said:
(Wed, May 18, 2011 06:19:18 AM)
|
|
| |
In the case of typedef:
string_t s1, s2;
This will be interpreted as
1. char *s1;
2. char *s2;
But in the case of pre-processor:
string_d s3, s4; <-- In this line 'string_d' will be replaced with 'char *'.
So, it will become
char *s3, s4; <-- Here watch carefully, s4 does't have '*'.
Therefore, s4 will be treated as 'char' only.
Note: #define preprocessor simply works like find-n-replace method. |
|
Bhimeswar said:
(Wed, Jul 27, 2011 06:24:55 PM)
|
|
| |
| Well done Sundar, you are rocking. |
|
Gowthami said:
(Wed, Feb 8, 2012 12:23:43 AM)
|
|
| |
| Thanku very much Mr sundar. |
|
|