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 - Pointers - Discussion

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

Read more:

"Everything should be made as simple as possible, but not simpler."
- Albert Einstein
23. 

If the size of integer is 4bytes, What will be the output of the program?

#include<stdio.h>

int main()
{
    int arr[] = {12, 13, 14, 15, 16};
    printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
    return 0;
}

[A]. 10, 2, 4[B]. 20, 4, 4
[C]. 16, 2, 2[D]. 20, 2, 2

Answer: Option D

Explanation:

No answer description available for this question.


Pondey Ramu said: (Fri, Jul 9, 2010 12:37:30 PM)    
 
The array elements are 5 and the size is 4 then multiplying both we get 20 that is the size of the array and second one is size of the each array element and third one is size of the first array element that is 4 only thats why anwer 20,4,4

Pradeep said: (Mon, Jul 26, 2010 02:30:13 AM)    
 
Thank you.

N Prathyusha said: (Tue, Jul 27, 2010 03:13:22 AM)    
 
The array elements are 5 each of size 4 bytes so it is 20.
Where as second is size of addres not the individual element so the size of int as declared is 4 so it is 4.
Then the final one is size of individual element i.e. size of first array element so it is 4.

Pradip Somase said: (Sat, Aug 21, 2010 07:50:48 PM)    
 
Thank you Pondey Ramu for description.

Srinivas.L said: (Wed, Sep 1, 2010 02:35:38 AM)    
 
The array elements are 5 each of size of 5 bytes. So it is 20.

Where as the second one is it will prints the address to store the int data type array so its value is 4.

And in last one is also it will prints the address of the arr[0], which is integer data type so its value is 4. So the final answer is 20 4 4.

Viraj said: (Sat, Nov 20, 2010 10:56:55 AM)    
 
Output will be 10 2 2 on 16 bit compiler.

Narendra said: (Thu, Jan 20, 2011 11:23:24 PM)    
 
The array elements are 5 each of size of 4 bytes. So it is 20,
where as second one is sizeof(*arr) means i.e pointer .all pointers occupies 4 bytesin 32 bit compiler so it is 4 bytes
and last one is same.

In 16 bit compiler it is 10 2 2;

Nirlep said: (Sun, Feb 6, 2011 05:51:13 AM)    
 
Why multiply by 4 it should be 2?

K Suresh said: (Fri, Jul 8, 2011 04:14:41 AM)    
 
THANK YOU PRATHYUSHA

Soumya said: (Tue, Jul 26, 2011 11:20:01 PM)    
 
Thank you pondey ramu.

Maya said: (Wed, Aug 10, 2011 04:16:49 PM)    
 
@nirlep:
It is given in the question. that int is of 4 bytes, so multiply by 4 and not 2

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!