adplus-dvertising
frame-decoration

Question

What is the output of the code given below?
#include <stdio.h>
    int main()
    {
        int ary[4] = {1, 2, 3, 4};
        int *p = ary + 3;
        printf("%d\n", p[-2]);
    }

a.

1

b.

2

c.

Compile time error

d.

Some garbage value

Posted under C Programming

Answer: (b).2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the code given below? #include <stdio.h> int main() { int ary[4] = {1, 2, 3, 4}; int *p = ary + 3; printf("%d\n",...

Similar Questions

Discover Related MCQs

Q. Different ways to initialize an array with all elements as zero are

Q. The elements in the array of the following code are

int array[5] = {5};

Q. Which of the following declaration is illegal?

Q. An array of similar data types which themselves are collection of dissimilar data type are

Q. Comment on an array of void data type:

Q. Which of the following operand can be applied to pointers p and q?

(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)

Q. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?

Q. Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)

Q. What type initialization is needed for the segment “ptr[3] = ‘3’;” to work?

Q. The syntax for constant pointer to address (i.e., fixed pointer address) is:

Q. The correct way to declare and assign a function pointer is done by:

(Assuming the function to be assigned is “int multi(int, int);”)

Q. Calling a function f with a an array variable a[3] where a is an array, is equivalent to

Q. How many number of pointer (*) does C have against a pointer variable declaration?

Q. Which of the following declaration throw run-time error?

Q. Comment on the following statement:
int (*a)[7];

Q. Comment on the 2 arrays regarding P and Q:

int *a1[8];
int *(a3[8]);
P. Array of pointers
Q. Pointer to an array

Q. Which of the following is not possible statically in C?

Q. What is the correct syntax to send a 3-dimensional array as a parameter?
(Assuming declaration int a[5][4][3];)

Q. Applications of multidimensional array are?

Q. To declare a 3 dimension array using pointers, which of the following is the correct syntax: