In a macro definition, to turn a token into a string containing the literal text of the token we need to prefix the token with a # sign. You can simply run the given code and verify.
Is it necessary that if we use %d format specifier with a string than it would give its address, and how is character giving output as 53?? Please explain!
string contains starting address of string constant "5". So, %d format specifier with a string gives its address.
Whereas character contains the constant '5'. Here, %c with character will give '5' and %d with character gives the ASCII value of '5'.
Note: Integer value of a character is equal to it's ASCII value.
When u declare string as a character pointer,it'll hold the base address of the character string,so when u print it with %d as format specifier,it's base address will be printed as an integer
When %d is passed as a format specifier and if we use it to print a character,it's ascii value will be printed and so as the ascii value of '5' is 53,so 53 is printed
and when integer is printed it will output the integer value
Macros can be defined using #define and u can also specify functions as a part of macro.
looks like a)
Only if the program is modified like the following, the answer will be (a)
Otherwise, the macro written within printf quotes will not take the proper values of x and format, so will lead to answer (d) None of these.
Please explain how it will be (a) and why we need to put #??
In a macro definition, to turn a token into a string containing the literal text of the token we need to prefix the token with a # sign. You can simply run the given code and verify.
Is it necessary that if we use %d format specifier with a string than it would give its address, and how is character giving output as 53?? Please explain!
string contains starting address of string constant "5". So, %d format specifier with a string gives its address.
Whereas character contains the constant '5'. Here, %c with character will give '5' and %d with character gives the ASCII value of '5'.
Note: Integer value of a character is equal to it's ASCII value.
yes. you are right.
thanks!
When u declare string as a character pointer,it'll hold the base address of the character string,so when u print it with %d as format specifier,it's base address will be printed as an integer
When %d is passed as a format specifier and if we use it to print a character,it's ascii value will be printed and so as the ascii value of '5' is 53,so 53 is printed
and when integer is printed it will output the integer value
Macros can be defined using #define and u can also specify functions as a part of macro.
Pages