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>
    void fun(int **p);
    
    int main()
    {
        int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
        int *ptr;
        ptr = &a[0][0];
        fun(&ptr);
        return 0;
    }
    void fun(int **p)
    {
        printf("%d\n", **p);
    }
    


  • Options
  • A. 1
  • B. 2
  • C. 3
  • D. 4

  • Correct Answer


  • Explanation
    Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; The variable a is declared as an multidimensional integer array with size of 3 rows 4 columns.

    Step 2: int *ptr; The *ptr is a integer pointer variable.

    Step 3: ptr = &a[0][0]; Here we are assigning the base address of the array a to the pointer variable *ptr.

    Step 4: fun(&ptr); Now, the &ptr contains the base address of array a.

    Step 4: Inside the function fun(&ptr); The printf("%d\n", **p); prints the value '1'.

    because the *p contains the base address or the first element memory address of the array a (ie. a[0])

    **p contains the value of *p memory location (ie. a[0]=1).

    Hence the output of the program is '1'


    More questions

    • 1. Bitwise can be used to reverse a sign of a number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 2. Is it necessary that in a function which accepts variable argument list there should be at least be one fixed argument?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 3. Bitwise can be used to generate a random number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 4. A function that receives variable number of arguments should use va_arg() to extract the last argument from the variable argument list.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. Bitwise & can be used to check if more than one bit in a number is on.

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.

    • Options
    • A. True
    • B. False
    • Discuss
    • 7. It is necessary that a header files should have a .h extension?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 8. Bitwise | can be used to set multiple bits in number.

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. Bitwise & can be used to check if a bit in number is set or not.

    • Options
    • A. True
    • B. False
    • Discuss
    • 10. A pointer union CANNOT be created

    • Options
    • A. Yes
    • B. No
    • Discuss


    Comments

    There are no comments.

Enter a new Comment