logo

CuriousTab

CuriousTab

Discussion


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


  • Options
  • A. 40 40
  • B. 20 40
  • C. 20
  • D. Error

  • Correct Answer
  • 20 40 

    Explanation
    In case of a conflict between a local variable and global variable, the local variable gets priority.

  • More questions

    • 1. What will be the output of the program?
      #include<stdio.h>
      #define MIN(x, y) (x<y)? x : y;
      int main()
      {
          int x=3, y=4, z;
          z = MIN(x+y/2, y-1);
          if(z > 0)
              printf("%d\n", z);
          return 0;
      }
      

    • Options
    • A. 3
    • B. 4
    • C. 0
    • D. No output
    • Discuss
    • 2. A pointer is

    • Options
    • A. A keyword used to create variables
    • B. A variable that stores address of an instruction
    • C. A variable that stores address of other variable
    • D. All of the above
    • Discuss
    • 3. one of elements of a structure can be a pointer to the same structure.

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. What is the purpose of "rb" in fopen() function used below in the code?
      FILE *fp;
      fp = fopen("source.txt", "rb");
      

    • Options
    • A. open "source.txt" in binary mode for reading
    • B. open "source.txt" in binary mode for reading and writing
    • C. Create a new file "source.txt" for reading and writing
    • D. None of above
    • Discuss
    • 5. Identify which of the following are declarations

      1 : extern int x;
      2 : float square ( float x ) { ... }
      3 : double pow(double, double);

    • Options
    • A. 1
    • B. 2
    • C. 1 and 3
    • D. 3
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      #include<stdlib.h>
      
      union employee
      {
          char name[15];
          int age;
          float salary;
      };
      const union employee e1;
      
      int main()
      {
          strcpy(e1.name, "K");
          printf("%s %d %f", e1.name, e1.age, e1.salary);
          return 0;
      }
      

    • Options
    • A. Error: RValue required
    • B. Error: cannot convert from 'const int *' to 'int *const'
    • C. Error: LValue required in strcpy
    • D. No error
    • Discuss
    • 7. Point out the error in the program in 16-bit platform?
      #include<stdio.h>
      
      int main()
      {
          struct bits
          {
              int i:40;
          }bit;
      
          printf("%d\n", sizeof(bit));
          return 0;
      }
      

    • Options
    • A. 4
    • B. 2
    • C. Error: Bit field too large
    • D. Error: Invalid member access in structure
    • Discuss
    • 8. Point out the error in the following program.
      #include<stdio.h>
      #include<stdarg.h>
      
      int main()
      {
          void display(int num, ...);
          display(4, 12.5, 13.5, 14.5, 44.3);
          return 0;
      }
      void display(int num, ...)
      {
          float c; int j;
          va_list ptr;
          va_start(ptr, num);
          for(j=1; j<=num; j++)
          {
              c = va_arg(ptr, float);
              printf("%f", c);
          }
      }
      

    • Options
    • A. Error: invalid va_list declaration
    • B. Error: var c data type mismatch
    • C. No error
    • D. No error and Nothing will print
    • Discuss
    • 9. What will be the output of the program (sample.c) given below if it is executed from the command line (Turbo C in DOS)?
      cmd> sample 1 2 3
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          int j;
          j = argv[1] + argv[2] + argv[3];
          printf("%d", j);
          return 0;
      }
      

    • Options
    • A. 6
    • B. sample 6
    • C. Error
    • D. Garbage value
    • Discuss
    • 10. va_list is an array that holds information needed by va_arg and va_end

    • Options
    • A. True
    • B. False
    • Discuss


    Comments

    There are no comments.

Enter a new Comment