1
GATE CSE 2006
MCQ (Single Correct Answer)
+2
-0.6
Consider this C code to swap two integers and these five statements:
S2: may generate a segmentation fault at runtime depending on the arguments passed
S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process
S4: implements the swap procedure correctly for some but not all valid input pointers
S5: may add or subtract integers and pointers.
void swap(int *px, int *py)
{
*px = *px - *py;
*py = *px + *py;
*px = *py - *px;
}
S1: will generate a compilation error S2: may generate a segmentation fault at runtime depending on the arguments passed
S3: correctly implements the swap procedure for all input pointers referring to integers stored in memory locations accessible to the process
S4: implements the swap procedure correctly for some but not all valid input pointers
S5: may add or subtract integers and pointers.
2
GATE CSE 2004
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
for(i=0; i < length; i++)
p[i] = s[length-i];
printf("%s",p);
The output of the program is
3
GATE CSE 2003
MCQ (Single Correct Answer)
+2
-0.6
Consider the C program shown below.
#include < stdio.h >
#define print(x) printf("%d ", x)
int x;
void Q(int z) {
z += x; print(z);
}
void P(int *y) {
int x = *y+2;
Q(x); *y = x-1;
print(x);
}
main(void) {
x = 5;
P(&x);
print(x);
}
The output of this program is4
GATE CSE 2001
MCQ (Single Correct Answer)
+2
-0.6
Consider the following three C functions:
[P1] int*g(void)
{
int x=10;
return(&x);
}
[P2] int*g(void)
{
int *px;
*px = 10;
return px;
}
[P3] int*g(void)
{
int *px
px =(int*)malloc (size of (int));
*px = 10;
return px;
}
Which of the above three functions are likely to cause problems with pointers?Questions Asked from Pointer and Structure in C (Marks 2)
Number in Brackets after Paper Indicates No. of Questions
GATE CSE Subjects
Theory of Computation
Operating Systems
Algorithms
Database Management System
Data Structures
Computer Networks
Software Engineering
Compiler Design
Web Technologies
General Aptitude
Discrete Mathematics
Programming Languages