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:

"Forgiveness is a virtue of the brave."
- Indira Gandhi
5. 

What will be the output of the program in TurboC?

#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10, j=20;
    const int *ptr = &i;
    printf(" i = %5X", ptr);
    printf(" ptr = %d", *ptr);
    ptr = &j;
    printf(" j = %5X", ptr);
    printf(" ptr = %d", *ptr);
    return 0;
}

[A]. i= FFE2 ptr=12 j=FFE4 ptr=24
[B]. i= FFE4 ptr=10 j=FFE2 ptr=20
[C]. i= FFE0 ptr=20 j=FFE1 ptr=30
[D]. Garbage value

Answer: Option D

Explanation:

No answer description available for this question.


Prashant Dixit said: (Sun, Jan 30, 2011 03:21:07 AM)    
 
There must be an error in this program because ptr is declared as of constant type and it can not be modified so value of j can not be stored in ptr.

Himanshu said: (Mon, Feb 21, 2011 10:17:35 AM)    
 
Can't get it. Please explain it in step by step procedure.

Sundar said: (Fri, Mar 18, 2011 12:15:37 PM)    
 
Output:

In Turbo C (under DOS - 16 bit platform)

i = FFF4 ptr = 10 j = FFF2 ptr = 20

In GCC (under Linux - 32 bit platform)

i = BF93368C ptr = 10 j = BF933688 ptr = 20

I hope this may be help you a bit. Have a nice day guys!

Ajay said: (Sat, Jul 9, 2011 02:11:26 PM)    
 
const int *ptr = &i;

It declares a pointer which points to integer of constant type.
Pointer is not constant.So we can change it.

Sharath said: (Thu, Jul 14, 2011 09:50:27 PM)    
 
We can change the value of constant pointer

Sharath said: (Thu, Jul 14, 2011 10:02:19 PM)    
 
int i=10;
const int *ptr=10; //correct
*ptr=&i; //correct
*ptr=10; //wrong

Siva Pavan said: (Wed, Sep 14, 2011 10:58:29 PM)    
 
Coming to 2nd printf statement, since in pointers &p represents address,*p represents value then clearly p is declared as pointer preccedding by const keyword so its value is always constant since it is addressed to x(p=&x) the only possible value for p is x value i.e 10.

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!