You are here:

C/Question on #define

Advertisement


Question
Dear Sir,
I have one doubt.
What does below statement mean?
#define sizeof(operator)
where operator can be int or float etc.
Does this statement meaningful and where it can be used?

Answer
In the c programming language sizeof is a reserved keyword. The sizeof operator returns the size of the type in bytes. #define may be used to define a macro replacement or a function-like macro. The line "#define sizeof(operator)" is probably part of a larger statement. #define takes the following forms:
# define identifier replacement-list new-line
# define identifier lparen identifier-listopt ) replacement-list new-line
# define identifier lparen ... ) replacement-list new-line
# define identifier lparen identifier-list , ... ) replacement-list new-line

Example:
//sizeof ( type-name )
printf("sizeof(char) = %lu\n", sizeof(char));
printf("sizeof(int) = %lu\n", sizeof(int));
printf("sizeof(float) = %lu\n", sizeof(float));
printf("sizeof(double) = %lu\n", sizeof(double));

Output:
sizeof(char) = 1
sizeof(int) = 4
sizeof(float) = 4
sizeof(double) = 8

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tony Nazzal

Expertise

I will answer any c language programming and syntax questions.

Experience

I have almost a decade of c programming experience.

Education/Credentials
I have a bachelor of science degree and several years of industry experience.

©2016 About.com. All rights reserved.