C Programming - Strings - Discussion
Discussion Forum : Strings - Find Output of Program (Q.No. 16)
16.
If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
Answer: Option
Explanation:
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
Discussion:
19 comments Page 2 of 2.
Praveen said:
1 decade ago
Additional Info:
If 3.14f mentioned like 3.14 then it will be assumed as double. So answer will be 8.
If 3.14f mentioned like 3.14 then it will be assumed as double. So answer will be 8.
(1)
MINDMASTER said:
9 years ago
ITS 1,1,4.
'A' IS A CHARACTER AND SIZEOF() WILL RETURN 1 BYTE. There is no question of sizeof(65).
'A' IS A CHARACTER AND SIZEOF() WILL RETURN 1 BYTE. There is no question of sizeof(65).
Bala said:
1 decade ago
@Neeraj:
How come sizeof('as') return 2 bytes? In single quote can ther be two characters?
How come sizeof('as') return 2 bytes? In single quote can ther be two characters?
Mantosh tiwari said:
1 decade ago
There are given that the int is of size 4 bytes so it will print 1 4 4 ..
Sattibabu said:
1 decade ago
sizeof(A)=size of(65)=sizeof(int)=2bytes
Srivibha said:
1 decade ago
It prints 1 1 4 in turbo c++ compiler.
Satyam rastogi said:
1 decade ago
65 is a integer it takes 2 bit.
Nigam said:
9 years ago
C++ compiler gives 1, 1, 4.
Sajal said:
1 decade ago
Please explain the reason.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers