C Programming GATE CS and IT previous year questions with Answer
Ques 31 Gate 2016 Set-1
The attributes of three arithmetic operators in some programming language are given below.
Operator | Precedence | Associativity | Arity |
---|---|---|---|
+ | High | Left | Binary |
- | Medium | Right | Binary |
* | Low | Left | Binary |
The value of the expression 2 - 5 + 1 - 7 * 3 in this language is __________ ?
a is the correct answer.
Ques 32 Gate 2016 Set-1
Consider the following C program
void mystery(int *ptra, int *ptrb)
{
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main()
{
int a=2016, b=0, c=4, d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%dn", a);
}
The output of the program _____________
a is the correct answer.
Ques 33 Gate 2016 Set-1
Consider the following proposed solution for the critical section problem. There are n
processes: P0 ...Pn−1. In the code, function pmax returns an integer not smaller than anyof its arguments. For all i, t[i] is initialized to zero.
:
do {
c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
for every j 6= i in {0,...,n-1} {
while (c[j]);
while (t[j] != 0 && t[j]<=t[i]);
}
Critical Section;
t[i]=0;
Remainder Section;
} while (true);
Which one of the following is TRUE about the above solution?
Ques 34 Gate 2016 Set-1
What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?
void n(x) {x = x * a; print(x);}
void m(y) {a = 1; a = y - a; n(a); print(a);}
void main() {m(a);}
Ques 35 Gate 2016 Set-1
The following function computes the maximum value contained in an integer array p[] of size n (n >= 1)
int max(int *p, int n)
{
int a=0, b=n-1;
while (__________)
{
if (p[a] <= p[b])
{
a = a+1;
}
else
{
b = b-1;
}
}
return p[a];
}
The missing loop condition is
Ques 36 Gate 2016 Set-1
Consider the following C program.
void f(int, short);
void main()
{
int i = 100;
short s = 12;
short *p = &s;
__________ ; // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
Ques 37 Gate 2015 Set-3
Consider the following C program.
int main( )
{
static int a[] = {10, 20, 30, 40, 50};
static int *p[] = {a, a+3, a+4, a+1, a+2};
int **ptr = p;
ptr++;
printf("%d%d", ptr - p, **ptr};
}
The output of the program is _________
a is the correct answer.
Ques 38 Gate 2015 Set-3
Consider the following two C code segments. Y and X are one and two dimensional arrays of size n and n × n respectively, where 2 ≤ n ≤ 10. Assume that in both code segments, elements of Y are initialized to 0 and each element X[i][j] of array X is initialized to i + j. Further assume that when stored in main memory all elements of X are in same main memory page frame.
Code segment 1:
// initialize elements of Y to 0
// initialize elements X[i][j] of X to i+j
for (i = 0; i < n; i++)
y[i] + = X[0][i];
Code segment 2:
// initialize elements of Y to 0
// initialize elements X[i][j] of X to i+j
for (i = 0; i < n; i++)
y[i] + = X[i][0];
Which of the following statements is/are correct?
S1: Final contents of array Y will be same in both code segments.
S2: Elements of array X accessed inside the for loop shown in
code segment 1 are contiguous in main memory.
S3: Elements of array X accessed inside the for loop shown in
code segment 2 are contiguous in main memory.
Ques 39 Gate 2015 Set-3
Consider the following C program segment.
int main( )
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0' ;
printf ("%s", s1);
}
What will be printed by the program?
Ques 40 Gate 2015 Set-2
Consider the following C function.
{
int x=1, k;
if (n==1) return x;
for (k=1; k < n; ++k)
x = x + fun(k) * fun(n – k);
return x;
}
The return value of fun(5) is __________.
a is the correct answer.