What will be the output of the following program in both C and C++? [code] #include<stdio.h> int main(int argc, char const *argv[]) { printf("%

Thanh Hoan

New member
What will be the output of the following program in both C and C++?
Code:
#include<stdio.h>
int main(int argc, char const *argv[])
{
	printf("%d\n", (int)sizeof('a'));
	return 0;
}
A. Output in C is 1 and in C++ is 4
B. Output in C is 4 and in C++ is 1
C. Output in C is 1 and in C++ is 1
D. Output in C is 4 and in C++ is 4
 
Answer: b
Explanation: In C a character is stored as int therefore the size of ‘a’ is printed as 4 whereas in C++ it is stored as char only therefore in C++ it prints 1.
 

Tìm kiếm

Back
Top