logo

CuriousTab

CuriousTab

Discussion


Home C Programming Constants See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        const int i=0;
        printf("%d\n", i++);
        return 0;
    }
    


  • Options
  • A. 10
  • B. 11
  • C. No output
  • D. Error: ++needs a value

  • Correct Answer
  • Error: ++needs a value 

    Explanation
    This program will show an error "Cannot modify a const object".

    Step 1: const int i=0; The constant variable 'i' is declared as an integer and initialized with value of '0'(zero).

    Step 2: printf("%d\n", i++); Here the variable 'i' is increemented by 1(one). This will create an error "Cannot modify a const object".

    Because, we cannot modify a const variable.


    More questions

    • 1. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp *e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 2. Point out the error in the program?
      #include<stdio.h>
      
      int main()
      {
          union a
          {
              int i;
              char ch[2];
          };
          union a z1 = {512};
          union a z2 = {0, 2};
          return 0;
      }
      

    • Options
    • A. Error: invalid union declaration
    • B. Error: in Initializing z2
    • C. No error
    • D. None of above
    • Discuss
    • 3. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss
    • 4. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample friday tuesday sunday
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          printf("%c", **++argv);
          return 0;
      }
      

    • Options
    • A. s
    • B. f
    • C. sample
    • D. friday
    • Discuss
    • 5. What is the purpose of fflush() function.

    • Options
    • A. flushes all streams and specified streams.
    • B. flushes only specified stream.
    • C. flushes input/output buffer.
    • D. flushes file buffer.
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char far *near *ptr1;
          char far *far *ptr2;
          char far *huge *ptr3;
          printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
          return 0;
      }
      

    • Options
    • A. 4, 4, 8
    • B. 4, 4, 4
    • C. 2, 4, 4
    • D. 2, 4, 8
    • Discuss
    • 7. Nested unions are allowed

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char huge *near *far *ptr1;
          char near *far *huge *ptr2;
          char far *huge *near *ptr3;
          printf("%d, %d, %d\n", sizeof(ptr1), sizeof(*ptr2), sizeof(**ptr3));
          return 0;
      }
      

    • Options
    • A. 4, 4, 4
    • B. 2, 4, 4
    • C. 4, 4, 2
    • D. 2, 4, 8
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      typedef void v;
      typedef int i;
      
      int main()
      {
          v fun(i, i);
          fun(2, 3);
          return 0;
      }
      v fun(i a, i b)
      {
          i s=2;
          float i;
          printf("%d,", sizeof(i));
          printf(" %d", a*b*s);
      }
      

    • Options
    • A. 2, 8
    • B. 4, 8
    • C. 2, 4
    • D. 4, 12
    • Discuss
    • 10. What will be the output of the program (myprog.c) given below if it is executed from the command line?
      cmd> myprog 1 2 3
      /* myprog.c */
      #include<stdio.h>
      #include<stdlib.h>
      
      int main(int argc, char **argv)
      {
          int i, j=0;
          for(i=0; i<argc; i++)
              j = j+atoi(argv[i]);
          printf("%d\n", j);
          return 0;
      }
      

    • Options
    • A. 123
    • B. 6
    • C. Error
    • D. "123"
    • Discuss


    Comments

    There are no comments.

Enter a new Comment