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 i;
    int fun();
    
    int main()
    {
        while(i)
        {
            fun();
            main();
        }
        printf("Hello\n");
        return 0;
    }
    int fun()
    {
        printf("Hi");
    }
    


  • Options
  • A. Hello
  • B. Hi Hello
  • C. No output
  • D. Infinite loop

  • Correct Answer
  • Hello 

    Explanation
    Step 1: int i; The variable i is declared as an integer type.

    Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any arguments and it returns an integer value.

    Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not execute the while block.

    Step 1: printf("Hello\n"); It prints "Hello".

    Hence the output of the program is "Hello".


    More questions

    • 1. Macros with arguments are allowed

    • Options
    • A. True
    • B. False
    • Discuss
    • 2. What will be the output of the program (in Turbo C)?
      #include<stdio.h>
      
      int fun(int *f)
      {
          *f = 10;
          return 0;
      }
      int main()
      {
          const int arr[5] = {1, 2, 3, 4, 5};
          printf("Before modification arr[3] = %d", arr[3]);
          fun(&arr[3]);
          printf("\nAfter modification arr[3] = %d", arr[3]);
          return 0;
      }
      

    • Options
    • A. Before modification arr[3] = 4
      After modification arr[3] = 10
    • B. Error: cannot convert parameter 1 from const int * to int *
    • C. Error: Invalid parameter
    • D. Before modification arr[3] = 4
      After modification arr[3] = 4
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          const int x=5;
          const int *ptrx;
          ptrx = &x;
          *ptrx = 10;
          printf("%d\n", x);
          return 0;
      }
      

    • Options
    • A. 5
    • B. 10
    • C. Error
    • D. Garbage value
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      int fun(int **ptr);
      
      int main()
      {
          int i=10;
          const int *ptr = &i;
          fun(&ptr);
          return 0;
      }
      int fun(int **ptr)
      {
          int j = 223;
          int *temp = &j;
          printf("Before changing ptr = %5x\n", *ptr);
          const *ptr = temp;
          printf("After changing ptr = %5x\n", *ptr);
          return 0;
      }
      

    • Options
    • A. Address of i
      Address of j
    • B. 10
      223
    • C. Error: cannot convert parameter 1 from 'const int **' to 'int **'
    • D. Garbage value
    • Discuss
    • 5. Point out the error in the program.
      #include<stdio.h>
      
      int main()
      {
          const int x;
          x=128;
          printf("%d\n", x);
          return 0;
      }
      

    • Options
    • A. Error: unknown data type const int
    • B. Error: const variable have been initialised when declared.
    • C. Error: stack overflow in x
    • D. No error
    • Discuss
    • 6. Point out the error in the program (in Turbo-C).
      #include<stdio.h>
      #define MAX 128
      
      int main()
      {
          const int max=128;
          char array[max];
          char string[MAX];
          array[0] = string[0] = 'A';
          printf("%c %c\n", array[0], string[0]);
          return 0;
      }
      

    • Options
    • A. Error: unknown max in declaration/Constant expression required
    • B. Error: invalid array string
    • C. None of above
    • D. No error. It prints A A
    • Discuss
    • 7. What will be the output of the program in TurboC?
      #include<stdio.h>
      int fun(int **ptr);
      
      int main()
      {
          int i=10, j=20;
          const int *ptr = &i;
          printf(" i = %5X", ptr);
          printf(" ptr = %d", *ptr);
          ptr = &j;
          printf(" j = %5X", ptr);
          printf(" ptr = %d", *ptr);
          return 0;
      }
      

    • Options
    • A. i= FFE2 ptr=12 j=FFE4 ptr=24
    • B. i= FFE4 ptr=10 j=FFE2 ptr=20
    • C. i= FFE0 ptr=20 j=FFE1 ptr=30
    • D. Garbage value
    • Discuss
    • 8. 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
    • Discuss
    • 9. Point out the error in 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", e1.name);    
          e1.age=85;
          printf("%d", e1.age);
          printf("%f", e1.salary);
          return 0;
      }
      

    • Options
    • A. Error: RValue required
    • B. Error: cannot modify const object
    • C. Error: LValue required in strcpy
    • D. No error
    • Discuss
    • 10. Point out the error in the program.
      #include<stdio.h>
      #define MAX 128
      
      int main()
      {
          char mybuf[] = "India";
          char yourbuf[] = "CURIOUSTAB";
          char *const ptr = mybuf;
          *ptr = 'a';
          ptr = yourbuf;
          return 0;
      }
      

    • Options
    • A. Error: unknown pointer conversion
    • B. Error: cannot convert ptr const value
    • C. No error
    • D. None of above
    • Discuss


    Comments

    There are no comments.

Enter a new Comment