logo

CuriousTab

CuriousTab

Discussion


Home C Programming Functions See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    int reverse(int);
    
    int main()
    {
        int no=5;
        reverse(no);
        return 0;
    }
    int reverse(int no)
    {
        if(no == 0)
            return 0;
        else
            printf("%d,", no);
        reverse (no--);
    }
    


  • Options
  • A. Print 5, 4, 3, 2, 1
  • B. Print 1, 2, 3, 4, 5
  • C. Print 5, 4, 3, 2, 1, 0
  • D. Infinite loop

  • Correct Answer
  • Infinite loop 

    Explanation
    Step 1: int no=5; The variable no is declared as integer type and initialized to 5.

    Step 2: reverse(no); becomes reverse(5); It calls the function reverse() with '5' as parameter.

    The function reverse accept an integer number 5 and it returns '0'(zero) if(5 == 0) if the given number is '0'(zero) or else printf("%d,", no); it prints that number 5 and calls the function reverse(5);.

    The function runs infinetely because the there is a post-decrement operator is used. It will not decrease the value of 'n' before calling the reverse() function. So, it calls reverse(5) infinitely.

    Note: If we use pre-decrement operator like reverse(--n), then the output will be 5, 4, 3, 2, 1. Because before calling the function, it decrements the value of 'n'.


    More questions

    • 1. Point out the error in the program.
      #include<stdio.h>
      const char *fun();
      
      int main()
      {
          *fun() = 'A';
          return 0;
      }
      const char *fun()
      {
          return "Hello";
      }
      

    • Options
    • A. Error: RValue required
    • B. Error: Lvalue required
    • C. Error: fun() returns a pointer const character which cannot be modified
    • D. No error
    • Discuss
    • 2. Which statement will you add to the following program to ensure that the program outputs "CuriousTab" on execution?
      #include<stdio.h>
      
      int main()
      {
          char s[] = "CuriousTab";
          char t[25];
          char *ps, *pt;
          ps = s;
          pt = t;
          while(*ps)
              *pt++ = *ps++;
      
          /* Add a statement here */
          printf("%s\n", t);
          return 0;
      }
      

    • Options
    • A. *pt='';
    • B. pt='\0';
    • C. pt='\n';
    • D. *pt='\0';
    • Discuss
    • 3. A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

    • Options
    • A. ABCD
    • B. DCBA
    • C. 0xABCD
    • D. Depends on big endian or little endian architecture
    • Discuss
    • 4. To print out a and b given below, which of the following printf() statement will you use?
      #include<stdio.h>
      
      float a=3.14;
      double b=3.14;
      

    • Options
    • A. printf("%f %lf", a, b);
    • B. printf("%Lf %f", a, b);
    • C. printf("%Lf %Lf", a, b);
    • D. printf("%f %Lf", a, b);
    • Discuss
    • 5. Which of the following function is more appropriate for reading in a multi-word string?

    • Options
    • A. printf();
    • B. scanf();
    • C. gets();
    • D. puts();
    • Discuss
    • 6. What will be the output of the program if the array begins at address 65486?
      #include<stdio.h>
      
      int main()
      {
          int arr[] = {12, 14, 15, 23, 45};
          printf("%u, %u\n", arr, &arr);
          return 0;
      }
      

    • Options
    • A. 65486, 65488
    • B. 65486, 65486
    • C. 65486, 65490
    • D. 65486, 65487
    • Discuss
    • 7. What will be the output of the program in Turbo C (under DOS)?
      #include<stdio.h>
      
      int main()
      {
          struct emp
          {
              char *n;
              int age;
          };
          struct emp e1 = {"Dravid", 23};
          struct emp e2 = e1;
          strupr(e2.n);
          printf("%s\n", e1.n);
          return 0;
      }
      

    • Options
    • A. Error: Invalid structure assignment
    • B. DRAVID
    • C. Dravid
    • D. No output
    • Discuss
    • 8. Does there any function exist to convert the int or float to a string?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. Which of the following special symbol allowed in a variable name?

    • Options
    • A. * (asterisk)
    • B. | (pipeline)
    • C. - (hyphen)
    • D. _ (underscore)
    • Discuss
    • 10. What will be the output of the program?
      #include<stdio.h>
      typedef unsigned long int uli;
      typedef uli u;
      
      int main()
      {
          uli a;
          u b = -1;
          a = -1;
          printf("%lu, %lu", a, b);
          return 0;
      }
      

    • Options
    • A. 4343445454, 4343445454
    • B. 4545455434, 4545455434
    • C. 4294967295, 4294967295
    • D. Garbage values
    • Discuss


    Comments

    There are no comments.

Enter a new Comment