IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C# Programming Java Programming
Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Typedef - Discussion

@ : Home > C Programming > Typedef > Yes / No Questions - 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;

[A]. Yes[B]. No

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.

Write your comments here:
Name *:     Email:


© 2008-2011 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Advertise     Contact us: info@indiabix.com     Follow us on twitter!