logo

CuriousTab

CuriousTab

Discussion


Home C Programming Pointers Comments

  • Question
  • What will be the output of the program?
    #include<stdio.h>
    
    int main()
    {
        void *vp;
        char ch=74, *cp="JACK";
        int j=65;
        vp=&ch;
        printf("%c", *(char*)vp);
        vp=&j;
        printf("%c", *(int*)vp);
        vp=cp;
        printf("%s", (char*)vp+2);
        return 0;
    }
    


  • Options
  • A. JCK
  • B. J65K
  • C. JAK
  • D. JACK

  • Correct Answer
  • JACK 


  • Pointers problems


    Search Results


    • 1. What will be the output of the program?
      #include<stdio.h>
      int *check(static int, static int);
      
      int main()
      {
          int *c;
          c = check(10, 20);
          printf("%d\n", c);
          return 0;
      }
      int *check(static int i, static int j)
      {
          int *p, *q;
          p = &i;
          q = &j;
          if(i >= 45)
              return (p);
          else
              return (q);
      }
      

    • Options
    • A. 10
    • B. 20
    • C. Error: Non portable pointer conversion
    • D. Error: cannot use static for function parameters
    • Discuss
    • 2. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          static char *s[] = {"black", "white", "pink", "violet"};
          char **ptr[] = {s+3, s+2, s+1, s}, ***p;
          p = ptr;
          ++p;
          printf("%s", **p+1);
          return 0;
      }
      

    • Options
    • A. ink
    • B. ack
    • C. ite
    • D. let
    • Discuss
    • 3. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          char str[20] = "Hello";
          char *const p=str;
          *p='M';
          printf("%s\n", str);
          return 0;
      }
      

    • Options
    • A. Mello
    • B. Hello
    • C. HMello
    • D. MHello
    • Discuss
    • 4. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
          int *p, *q;
          p = &arr[1][1][1];
          q = (int*) arr;
          printf("%d, %d\n", *p, *q);
          return 0;
      }
      

    • Options
    • A. 8, 10
    • B. 10, 2
    • C. 8, 1
    • D. Garbage values
    • Discuss
    • 5. What will be the output of the program?
      #include<stdio.h>
      
      int main()
      {
          int i, a[] = {2, 4, 6, 8, 10};
          change(a, 5);
          for(i=0; i<=4; i++)
              printf("%d, ", a[i]);
          return 0;
      }
      void change(int *b, int n)
      {
          int i;
          for(i=0; i<n; i++)
              *(b+1) = *(b+i)+5;
      }
      

    • Options
    • A. 7, 9, 11, 13, 15
    • B. 2, 15, 6, 8, 10
    • C. 2 4 6 8 10
    • D. 3, 1, -1, -3, -5
    • Discuss
    • 6. In the following program add a statement in the function fact() such that the factorial gets stored in j.
      #include<stdio.h>
      void fact(int*);
      
      int main()
      {
          int i=5;
          fact(&i);
          printf("%d\n", i);
          return 0;
      }
      void fact(int *j)
      {
          static int s=1;
          if(*j!=0)
          {
              s = s**j;
              *j = *j-1;
              fact(j);
              /* Add a statement here */
          }
      }
      

    • Options
    • A. j=s;
    • B. *j=s;
    • C. *j=&s;
    • D. &j=s;
    • 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. Which of the statements is correct about the program?
      #include<stdio.h>
      
      int main()
      {
          int arr[3][3] = {1, 2, 3, 4};
          printf("%d\n", *(*(*(arr))));
          return 0;
      }
      

    • Options
    • A. Output: Garbage value
    • B. Output: 1
    • C. Output: 3
    • D. Error: Invalid indirection
    • Discuss
    • 9. 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
    • 10. 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


    Comments

    There are no comments.

Enter a new Comment