logo

CuriousTab

CuriousTab

Discussion


Home C Programming Constants See What Others Are Saying!
  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        int y=128;
        const int x=y;
        printf("%d\n", x);
        return 0;
    }
    


  • Options
  • A. 128
  • B. Garbage value
  • C. Error
  • D. 0

  • Correct Answer
  • 128 

    Explanation
    Step 1: int y=128; The variable 'y' is declared as an integer type and initialized to value "128".

    Step 2: const int x=y; The constant variable 'x' is declared as an integer and it is initialized with the variable 'y' value.

    Step 3: printf("%d\n", x); It prints the value of variable 'x'.

    Hence the output of the program is "128"


    More questions

    • 1. What will be the output of the program in Turbo C?
      #include<stdio.h>
      
      int main(int argc, char *argv, char *env[])
      {
          int i;
          for(i=1; i<argc; i++)
              printf("%s\n", env[i]);
          return 0;
      }
      

    • Options
    • A. List of all environment variables
    • B. List of all command-line arguments
    • C. count of command-line arguments
    • D. Error: cannot have more than two arguments in main()
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      int fun(int, int);
      typedef int (*pf) (int, int);
      int proc(pf, int, int);
      
      int main()
      {
          printf("%d\n", proc(fun, 6, 6));
          return 0;
      }
      int fun(int a, int b)
      {
         return (a==b);
      }
      int proc(pf p, int a, int b)
      {
         return ((*p)(a, b));
      }
      

    • Options
    • A. 6
    • B. 1
    • C. 0
    • D. -1
    • Discuss
    • 3. In the following program add a statement in the function fun() such that address of a gets stored in j?
      #include<stdio.h>
      int main()
      {
          int *j;
          void fun(int**);
          fun(&j);
          return 0;
      }
      void fun(int **k)
      {
          int a=10;
          /* Add a statement here */
      }
      

    • Options
    • A. **k=a;
    • B. k=&a;
    • C. *k=&a
    • D. &k=*a
    • Discuss
    • 4. The '->' operator can be used to access structures elements using a pointer to a structure variable only

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. What are the types of linkages?

    • Options
    • A. Internal and External
    • B. External, Internal and None
    • C. External and None
    • D. Internal
    • Discuss
    • 6. Out of fgets() and gets() which function is safe to use?

    • Options
    • A. gets()
    • B. fgets()
    • Discuss
    • 7. A structure can be nested inside another structure.

    • Options
    • A. True
    • B. False
    • Discuss
    • 8. What will be the output of the program (sample.c) given below if it is executed from the command line?
      cmd> sample one two three
      /* sample.c */
      #include<stdio.h>
      
      int main(int argc, char *argv[])
      {
          int i=0;
          i+=strlen(argv[1]);
          while(i>0)
          {
              printf("%c", argv[1][--i]);
          }
          return 0;
      }
      

    • Options
    • A. three two one
    • B. owt
    • C. eno
    • D. eerht
    • Discuss
    • 9. Which of the following statement is True?

    • Options
    • A. User has to explicitly define the numeric value of enumerations
    • B. User has a control over the size of enumeration variables.
    • C. Enumeration can have an effect local to the block, if desired
    • D. Enumerations have a global effect throughout the file.
    • Discuss
    • 10. Point out the error in the program?
      struct emp
      {
          int ecode;
          struct emp *e;
      };
      

    • Options
    • A. Error: in structure declaration
    • B. Linker Error
    • C. No Error
    • D. None of above
    • Discuss


    Comments

    There are no comments.

Enter a new Comment