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 Java Programming
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 - Const - Discussion

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

Read more:

"Everything you can imagine is real."
- Pablo Picasso
2. 

What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

union employee
{
    char name[15];
    int age;
    float salary;
};
const union employee e1;

int main()
{
    strcpy(e1.name, "K");
    printf("%s %d %f", e1.name, e1.age, e1.salary);
    return 0;
}

[A]. Error: RValue required
[B]. Error: cannot convert from 'const int *' to 'int *const'
[C]. Error: LValue required in strcpy
[D]. No error

Answer: Option A

Explanation:

The output will be (in 16-bit platform DOS):

K 75 0.000000


Rishabh said: (Wed, Nov 10, 2010 12:38:49 PM)    
 
How can 75 be the value of e1.age ?

Div said: (Mon, Dec 6, 2010 10:11:30 AM)    
 
I would also like to know how e1.age gets the value 75 ?

Nishant Sinha said: (Mon, Jan 24, 2011 12:54:49 PM)    
 
Since union makes use of shared memory. So it allocates the memory for datatype which will take highest memory i.e int. So it will allocate 16 bit in turbo c++ and 32 bits in unix compiler. So the character 'k' will be stored in memory as the bit value of 75 as ascii value of k is 75. Since the int is also sharing this memory so it will read the same memory content with a padding of some zeros to make it 2 bytes in turboo or 4 bytes in unix.

Ajay said: (Wed, Feb 16, 2011 10:07:14 AM)    
 
Please explain in detail.

Maheep Sharma said: (Wed, Feb 16, 2011 10:44:10 AM)    
 
Why float is not sharing the same memory and not outputting as 75.000000 ?

Archana said: (Tue, Sep 20, 2011 11:19:57 AM)    
 
Can anyone explain why float doesn't take 75. 000000?

Sona said: (Thu, Nov 17, 2011 11:39:35 AM)    
 
I think ascii value don't take the float value, so float value is 0.000000.

Rakesh said: (Fri, Dec 9, 2011 09:01:03 AM)    
 
Please explain in detail.

Nandu said: (Tue, Dec 27, 2011 12:37:51 AM)    
 
The ascii value of K=75, ascii deosnt take float value so float value z 0.000000 thats it. Once see ascii table it will be easy for you guys.

Asha said: (Fri, Feb 3, 2012 05:31:49 PM)    
 
Since in union memory of highest datatype is allocated then why the memory of float datatype is allocated? why it has allacated 2 bytes?

Write your comments here:
Name *:     Email:


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

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