Home / CSE MCQs / C-MCQs :: Discussion

Discussion :: C-MCQs

  1. 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;
    }
  2. A.
    Compile time error
    B.
    10    20
    C.
    Undefined value
    D.
    10

    View Answer

    Workspace

    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