MCQs
No answer description available for this question.
No answer description available for this question.
The statement str = "Kanpur"; generates the LVALUE required error. We have to
use strcpy function to copy a string.
To remove error we have to change this statement str = "Kanpur"; to strcpy(str, "Kanpur");
The program prints the string "anpur"
No answer description available for this question.
If the size of pointer is 32 bits What will be the output of the program ?
#include<stdio.h>
int main()
{
char a[] = "Visual C++";
char *b = "Visual C++";
printf("%d, %d\n", sizeof(a), sizeof(b));
printf("%d, %d", sizeof(*a), sizeof(*b));
return 0;
}
A. 10, 2
2, 2
B. 10, 4
1, 2
C. 11, 4
1, 1
D. 12, 2
2, 2
Answer: (C)
No answer description available for this question.
Step 1: char ch = 'A'; The variable ch is declared as an character type and
initialized with value 'A'.
Step 2:
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));
The sizeof function returns the size of the given expression.
sizeof(ch) becomes sizeof(char). The size of char is 1 byte.
sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).
sizeof(3.14f). The size of float is 4 bytes.
Hence the output of the program is 1, 4, 4
The function printf() returns the number of charecters printed on the console.
Step 1: char a[] = "�"; The variable a is declared as an array of characters and it
initialized with "�". It denotes that the string is empty.
Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns
'0'(zero). Hence the if condition is failed.
In the else part it prints "The string is not empty".
Step 1:
printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));
The sizeof function returns the size of the given expression.
sizeof(3.0f) is a floating point constant. The size of float is 4 bytes
sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes
sizeof(3.0) is a double constant. The size of double is 8 bytes
Hence the output of the program is 4,2,8
Note: The above program may produce different output in other platform due to the platform dependency of C compiler.
In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.
No answer description available for this question.
No answer description available for this question.