Consider the following code segment:int arr[] = {0,1,2,3,4};
int i = 1, *ptr;
ptr = arr + 2;Arrange the following printf statements in increasing order of their output:
(a) printf("%d", ptr[i]);
(b) printf("%d", ptr[i+1]);
(c) printf("%d", ptr[-i]);
(d) printf("%d", ptr[-i+1]);
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: B. (c), (d), (a), (b)
Explanation
ptr points to arr[2]. ptr[1] = 3, ptr[2] = 4, ptr[−1] = 1, ptr[0] = 2. Increasing: (c) 1, (d) 2, (a) 3, (b) 4.More Programming Languages and Computer Graphics questions
- Statement (I): A friend function and the member functions of a friend class can directly access private and protected data. Statement (II):…
- Match List I with List IIList I List II A. Bezier curves I. 3-D objects that have translational/rotational symmetry B. B-Splines II. Fracta…
- What will be the output of the following code?#include <stdio.h> int main() { int a, b, c; a = 0x10; b = 010; c = a + b; printf("%d", c); r…
- A three-dimensional array in C++ is declared as int A[a][b][c]. Array elements are stored in row-major order and indexing begins from 0. Th…
- What is the output of the following code?main() { struct s1 { char *z; int i; struct s1 *p; }; static struct s1 a[] = { {"Nagpur", 1, a+1},…
- The Sutherland-Hodgeman method is used on