1
GATE CSE 2012
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C code segment.
int a, b, c = 0;
void prtFun(void);
main( )
{
static int a = 1; /* Line 1 */
prtFun();
a + = 1;
prtFun();
printf("\n %d %d ", a, b);
}
void prtFun(void)
{
static int a=2;   /* Line 2 */
int b=1;
a+ = ++b;
printf("\n %d %d ", a, b);
}
What output will be generated by the given code segment?
A
\eqalign{ & 3\,\,1 \cr & 4\,\,1 \cr & 4\,\,2 \cr}
B
\eqalign{ & 4\,\,2 \cr & 6\,\,1 \cr & 6\,\,1 \cr}
C
\eqalign{ & 4\,\,2 \cr & 6\,\,2 \cr & 2\,\,0 \cr}
D
\eqalign{ & 3\,\,1 \cr & 5\,\,2 \cr & 5\,\,2 \cr}
2
GATE CSE 2012
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C code segment.
int a, b, c = 0;
void prtFun(void);
main( )
{
static int a = 1; /* Line 1 */
prtFun();
a + = 1;
prtFun();
printf("\n %d %d ", a, b);
}
void prtFun(void)
{
static int a=2;   /* Line 2 */
int b=1;
a+ = ++b;
printf("\n %d %d ", a, b);
}
What output will be generated by the given code segment if:
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
A
\eqalign{ & 3\,\,1 \cr & 4\,\,1 \cr & 4\,\,2 \cr}
B
\eqalign{ & 4\,\,2 \cr & 6\,\,1 \cr & 6\,\,1 \cr}
C
\eqalign{ & 4\,\,2 \cr & 6\,\,2 \cr & 2\,\,0 \cr}
D
\eqalign{ & 4\,\,2 \cr & 4\,\,2 \cr & 2\,\,0 \cr}
3
GATE CSE 2008
MCQ (Single Correct Answer)
+2
-0.6
What is printed by the following C program?
#include < stdio.h >
int f(int x, int *py, int **ppz)
{
int y, z;
**ppz += 1;
z  = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}

void main()
{
int c, *b, **a;
c = 4;
b = &c;
a = &b;
printf( "%d", f(c,b,a));
getchar();
}
A
18
B
19
C
21
D
22
4
GATE CSE 2006
MCQ (Single Correct Answer)
+2
-0.6
Consider this C code to swap two integers and these five statements:
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.
A
S1
B
S2 and S3
C
S2 and S4
D
S2 and S5
GATE CSE Subjects
Discrete Mathematics
Programming Languages
Theory of Computation
Operating Systems
Digital Logic
Computer Organization
Database Management System
Data Structures
Computer Networks
Algorithms
Compiler Design
Software Engineering
Web Technologies
General Aptitude
EXAM MAP
Joint Entrance Examination
JEE MainJEE AdvancedWB JEEBITSATMHT CET
Medical
NEET
Graduate Aptitude Test in Engineering
GATE CSEGATE ECEGATE EEGATE MEGATE CEGATE PIGATE IN