Computer Science, asked by Anonymous, 1 year ago

OT ATTEMPTED
6. What is the output of the following 'C' program ?

#include
void main ()
{
const int x = 5;
const int *ptrx;
ptrx = &x;
*ptrx = 10;
printf("%d", x);
}

A. 5
B. Compilation Error
C. 10
D. Garbage value

Answers

Answered by siddhartharao77
2

Answer: Option(B) - Compilation Error.

Explanation:

#include<stdio.h>

int main()

{

const int x = 5;

const int *ptrx;

ptrx = &x; // ptrx is pointer is constant

*ptrx = 10; // Cannot be modified using ptrx.

printf("%d",x);

}


Output:

Error : assignment of read-only location 'ptrx'.


Hope it helps!

Similar questions