logo

CuriousTab

CuriousTab

Discussion


Home C Programming Arrays See What Others Are Saying!
  • Question
  • What will be the output of the program if the array begins at 65472 and each integer occupies 2 bytes?
    #include<stdio.h>
    
    int main()
    {
        int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};
        printf("%u, %u\n", a+1, &a+1);
        return 0;
    }
    


  • Options
  • A. 65474, 65476
  • B. 65480, 65496
  • C. 65480, 65488
  • D. 65474, 65488

  • Correct Answer
  • 65480, 65496 

    Explanation
    Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions.

    Step 2: printf("%u, %u\n", a+1, &a+1);

    The base address(also the address of the first element) of array is 65472.

    For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a. Hence 65472 + (4 ints * 2 bytes) = 65480

    Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints. Therefore, &a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes".

    Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496

    Hence the output of the program is 65480, 65496


    More questions

    • 1. 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
    • 2. 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
    • 3. 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
    • 4. 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
    • 5. va_list is an array that holds information needed by va_arg and va_end

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. A structure can contain similar or dissimilar elements

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. Which of the statements is correct about the program?
      #include<stdio.h>
      
      int main()
      {
          float a=3.14;
          char *j;
          j = (char*)&a;
          printf("%d\n", *j);
          return 0;
      }
      

    • Options
    • A. It prints ASCII value of the binary number present in the first byte of a float variable a.
    • B. It prints character equivalent of the binary number present in the first byte of a float variable a.
    • C. It will print 3
    • D. It will print a garbage value
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int i=4;
          switch(i)
          {
              default:
                 printf("This is default\n");
              case 1:
                 printf("This is case 1\n");
                 break;
              case 2:
                 printf("This is case 2\n");
                 break;
              case 3:
                 printf("This is case 3\n");
          }
          return 0;
      }
      

    • Options
    • A. This is default
      This is case 1
    • B. This is case 3
      This is default
    • C. This is case 1
      This is case 3
    • D. This is default
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int a = 300, b, c;
          if(a >= 400)
              b = 300;
          c = 200;
          printf("%d, %d, %d\n", a, b, c);
          return 0;
      }
      

    • Options
    • A. 300, 300, 200
    • B. Garbage, 300, 200
    • C. 300, Garbage, 200
    • D. 300, 300, Garbage
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int x = 10, y = 20;
          if(!(!x) && x)
              printf("x = %d\n", x);
          else
              printf("y = %d\n", y);
          return 0;
      }
      

    • Options
    • A. y =20
    • B. x = 0
    • C. x = 10
    • D. x = 1
    • Discuss


    Comments

    There are no comments.

Enter a new Comment