C Programming - Const - Discussion

Discussion Forum : Const - Find Output of Program (Q.No. 5)
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;
}
i= FFE2 ptr=12 j=FFE4 ptr=24
i= FFE4 ptr=10 j=FFE2 ptr=20
i= FFE0 ptr=20 j=FFE1 ptr=30
Garbage value
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
28 comments Page 2 of 3.

Surbhi said:   1 decade ago
% 5x here x is for hexadecimal value of ptr that has assigned to I and 5 specifies the width of ptr at least 5 digits wide (space also included).

Karun das said:   1 decade ago
Yes, here an object is a constant, we can't change pointer here,

Totally confusion, please correct me if I am thinking in incorrect way.

Ajay said:   1 decade ago
const int *ptr = &i;

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

Ritesh lenka said:   1 decade ago
Here the int value that pointed by ptr is const. Not the ptr. When we declare int const *ptr, then ptr is consider as a constant.

Aditya said:   7 years ago
What will be the output of the following statement with an explanation?

printf("%X%x%ci%x",11,10,'s',12);

Sharath said:   1 decade ago
int i=10;
const int *ptr=10; //correct
*ptr=&i; //correct
*ptr=10; //wrong

Selvakumar said:   8 years ago
I m not getting the given code. Please anyone explain this.

Himanshu said:   1 decade ago
Can't get it. Please explain it in step by step procedure.

Bhavani said:   9 years ago
How FFE4 and FFE2 came in output? Please explain me.

Pooja said:   6 years ago
I can't understand the output. Please explain me.


Post your comments here:

Your comments will be displayed after verification.