logo

CuriousTab

CuriousTab

Discussion


Home C Programming Arrays See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        int a[5] = {5, 1, 15, 20, 25};
        int i, j, m;
        i = ++a[1];
        j = a[1]++;
        m = a[i++];
        printf("%d, %d, %d", i, j, m);
        return 0;
    }
    


  • Options
  • A. 2, 1, 15
  • B. 1, 2, 5
  • C. 3, 2, 15
  • D. 2, 3, 20

  • Correct Answer
  • 3, 2, 15 

    Explanation
    Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initialized to

    a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .

    Step 2: int i, j, m; The variable i,j,m are declared as an integer type.

    Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

    Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

    Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3)

    Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the variables i, j, m

    Hence the output of the program is 3, 2, 15


    More questions

    • 1. size of union is size of the longest element in the union

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Bitwise & can be used to divide a number by powers of 2

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. Assuming, integer is 2 byte, What will be the output of the program?
      #include;
      
      int main()
      {
          printf("%x\n", -1>>1);
          return 0;
      }
      

    • Options
    • A. ffff
    • B. 0fff
    • C. 0000
    • D. fff0
    • Discuss
    • 4. What is the output of the program given below?
      #include<stdio.h>
      int main()
      {
          enum status { pass, fail, atkt};
          enum status stud1, stud2, stud3;
          stud1 = pass;
          stud2 = atkt;
          stud3 = fail;
          printf("%d, %d, %d\n", stud1, stud2, stud3);
          return 0;
      }
      

    • Options
    • A. 0, 1, 2
    • B. 1, 2, 3
    • C. 0, 2, 1
    • D. 1, 3, 2
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          char ch;
          ch = 'A';
          printf("The letter is");
          printf("%c", ch >= 'A' && ch <= 'Z'? ch + 'a' - 'A':ch);
          printf("Now the letter is");
          printf("%c\n", ch >= 'A' && ch <= 'Z'? ch : ch + 'a' - 'A');
          return 0;
      }
      

    • Options
    • A. The letter is a
      Now the letter is A
    • B. The letter is A
      Now the letter is a
    • C. Error
    • D. None of above
    • Discuss
    • 6. What will be the output of the program?
      #include<stdio.h>
      int main()
      {
          int k, num=30;
          k = (num>5? (num <=10? 100 : 200): 500);
          printf("%d\n", num);
          return 0;
      }
      

    • Options
    • A. 200
    • B. 30
    • C. 100
    • D. 500
    • Discuss
    • 7. If a function contains two return statements successively, the compiler will generate warnings. Yes/No?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char *str;
          str = "%s";
          printf(str, "K\n");
          return 0;
      }
      

    • Options
    • A. Error
    • B. No output
    • C. K
    • D. %s
    • Discuss
    • 9. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str1[] = "India";
          char str2[] = "CURIOUSTAB";
          char *s1 = str1, *s2=str2;
          while(*s1++ = *s2++)
              printf("%s", str1);
      
          printf("\n");
          return 0;
      }
      

    • Options
    • A. CuriousTab
    • B. BndiaBIdiaCURIOUSTABia
    • C. India
    • D. (null)
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int x=30, *y, *z;
          y=&x; /* Assume address of x is 500 and integer is 4 byte size */
          z=y;
          *y++=*z++;
          x++;
          printf("x=%d, y=%d, z=%d\n", x, y, z);
          return 0;
      }
      

    • Options
    • A. x=31, y=502, z=502
    • B. x=31, y=500, z=500
    • C. x=31, y=498, z=498
    • D. x=31, y=504, z=504
    • Discuss


    Comments

    There are no comments.

Enter a new Comment