IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

C Programming - Strings - Discussion

@ : Home > C Programming > Strings > Find Output of Program - Discussion

Read more:

"When ambition ends, happiness begins."
- (Proverb)
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;
}

[A]. 1, 2, 4[B]. 1, 4, 4
[C]. 2, 2, 4[D]. 2, 4, 8

Answer: Option A

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


Praveen said: (Mon, Sep 13, 2010 05:06:22 PM)    
 
Additional Info:

If 3.14f mentioned like 3.14 then it will be assumed as double. So answer will be 8.

Srivibha said: (Wed, Nov 3, 2010 10:06:14 PM)    
 
It prints 1 1 4 in turbo c++ compiler.

Mantosh Tiwari said: (Fri, Nov 12, 2010 04:49:12 AM)    
 
There are given that the int is of size 4 bytes so it will print 1 4 4 ..

Hitesh Bhateja said: (Wed, Jan 19, 2011 05:19:52 PM)    
 
@SRIVIBHA,

I agree with you..

sizeof('A') returns 1 byte because A is character not integer so it always returns character value.

Sajal said: (Tue, Sep 13, 2011 10:25:26 PM)    
 
Please explain the reason.

Sattibabu said: (Fri, Nov 11, 2011 06:34:27 PM)    
 
sizeof(A)=size of(65)=sizeof(int)=2bytes

Neeraj said: (Wed, Mar 7, 2012 05:58:16 PM)    
 
sizeof('A')=it will always return 1 since there can be only 1 character in single quotes '' and the size of char is 1 bytes.

sizeof("A")=it will return 2 bytes there are 2 characters in it (A and \0)as the compiler inserts the null character automatically.

Bala said: (Sun, Jul 8, 2012 05:47:47 PM)    
 
@Neeraj:
How come sizeof('as') return 2 bytes? In single quote can ther be two characters?

Yogesh said: (Tue, Oct 2, 2012 11:53:33 PM)    
 
In single quotation there can be only character. Correct. Ok then sizeof ('A') will be simply sizeof (char). So it will definitely return 1 byte. Obviously.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!