Sail E0 Webinar
Question
What is the output of this C code?
void foo(const int *);
int main()
{
const int i = 10;
printf("%d ", i);
foo(&i);
printf("%d", i);
}
void foo(const int *i)
{
*i = 20;
}
Options:
A .  Compile time error
B .  10    20
C .  Undefined value
D .  10
Answer: Option A


Cannot change a const type value.
Output:
$ cc pgm1.c
pgm1.c: In function 'foo':
pgm1.c:13: error: assignment of read-only location '*i'



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers