edited by
5,854 views
2 votes
2 votes
include <stdio.h>
int main()
{
    int a[][3] = {1, 2, 3, 4, 5, 6};
    int (*ptr)[3] = a;
    printf("%d %d ", (*ptr)[1], (*ptr)[2]);
    ++ptr;
    printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
    return 0;
}



(a) 2 3 5 6

(b) 2 3 4 5

(c) 4 5 0 0

(d) none of the above

edited by

2 Answers

Best answer
6 votes
6 votes
include <stdio.h>
int main()
{
    int a[][3] = {1, 2, 3, 4, 5, 6};
    int (*ptr)[3] = a;
    printf("%d %d ", (*ptr)[1], (*ptr)[2]);
    ++ptr;
    printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
    return 0;
1 2 3
4 5 6
 int (*ptr)[3] = a; // here ptr is pointer to an array of 3 integers.

At first ptr is pointing to first row. Say address of 1st row is 2000

So, (*ptr)[1]=*(2004)=2 and (*ptr)[2]=*(2008)=3

Now ++ptr is updating pointer to next row. So, Now ptr pointing to address 2000+3*4=2012

So, Now So, (*ptr)[1]=*(2016)=5 and (*ptr)[2]=*(2020)=6

selected by
0 votes
0 votes

The correct answer is (a) 2 3 5 6.

Explanation:

  • -> Initially, ptr points to the first array in a, so (*ptr)[1] prints the second element (2) and (*ptr)[2] prints the third element (3).
  • -> After incrementing ptr, it now points to the second array in a, so (*ptr)[1] prints the second element (5) and (*ptr)[2] prints the third element (6)

Related questions

0 votes
0 votes
0 answers
1
Anirudh Kaushal asked Apr 6, 2022
191 views
#include<stdio.h struct marks { int p:3; int c:3; int m:2; }; void main() { struct marks s = {2, -6, 5}; printf("%d %d %d", s.p, s.c, s.m); }What does p:3 means here ?
0 votes
0 votes
1 answer
2
Parshu gate asked Nov 19, 2017
359 views
#include<stdio.h>int main(){ int a=2;if(a==2){ a=~a+2<<1; printf("%d",a);}}
2 votes
2 votes
2 answers
3
Parshu gate asked Nov 5, 2017
1,293 views
OPTIONSA)7,19 B) 10,1 C) 10,23 D)10,32
1 votes
1 votes
1 answer
4
Archies09 asked Apr 23, 2017
3,179 views
What will be the output of the program?#include<stdio.h int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4...