Discussion :: C-MCQs
-
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;
}
Answer : Option A
Explanation :
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'
Be The First To Comment