1- Union Person { char name[30]; //30 bytes int age; float height; }; How many b
ID: 3611189 • Letter: 1
Question
1- Union Person{
char name[30]; //30 bytes
int age;
float height;
};
How many bytes will skip after executing ptr = ptr +1.
Union Person abc, *ptr;
Ptr = &abc;
ptr = ptr +1;
? 30 bytes will skip after executing ptr = ptr +1.
? 31 bytes will skip after executing ptr = ptr +1.
? 32 bytes will skip after executing ptr = ptr +1.
? 38 bytes will skip after executing ptr = ptr +1.
2- char (*ptrString)[4][2];
How many bytes will be skipped by the statement ptrString += 2?
? 16
? 1
? 4
? 8
Union Person
{
char name[30]; //30 bytes
int age;
float height;
};
How many bytes will skip after executing ptr = ptr +1.
Union Person abc, *ptr;
Ptr = &abc;
ptr = ptr +1;
? 30 bytes will skip after executing ptr = ptr +1.
? 31 bytes will skip after executing ptr = ptr +1.
? 32 bytes will skip after executing ptr = ptr +1.
? 38 bytes will skip after executing ptr = ptr +1.
2- char (*ptrString)[4][2];
How many bytes will be skipped by the statement ptrString += 2?
? 16
? 1
? 4
? 8
Explanation / Answer
Union Person{
char name[30]; //30 bytes
int age;
float height;
};
How many bytes will skip after executing ptr = ptr +1.
Union Person abc, *ptr;
Ptr = &abc;
ptr = ptr +1;
? 30 bytes will skip after executing ptr = ptr+1.
? 31 bytes will skip after executing ptr = ptr +1.
? 32 bytes will skip after executing ptr = ptr +1.
? 38 bytes will skip after executing ptr = ptr +1.
Reason: It is 30 bytes since the size of the aboveUNION is 30 bytes. When ptr= ptr+1 is executed it skips 30bytes
2- char (*ptrString)[4][2];
How many bytes will be skipped by the statement ptrString += 2?
? 16
? 1
? 4
? 8
Initially the pointer points to the starting of the array,...whenptrString +=2 is executed, the pointer moves to the third positioni.e ptrString[2]..
therefore it skips(ptrString[0][0], ptrString[0][1],ptrString[1][0],ptrString[1][1])and moves to position of ptrString[2][..]
Therefore it moved 4* (size of pointers tochar)
= 4* size of int
= 4 * 2
=8
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.