Q11
Consider the following C program segment.
#include <stdio.h>
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
}What will be printed by the program?
Show answer without attempting
Answer: C
GATE CS · 29 questions
29 Programming and Data Structures questions from GATE CS papers (2015), each with the official answer key. Answer any question right here and it is marked straight away, or practise them one at a time.
#include <stdio.h>
int main()
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
}Answer: C
Answer: 612 to 613
Answer: 199
Answer: B
Answer: C
Answer: D
Answer: 28
void get(int n)
{
if (n<1) return;
get(n-1);
get(n-3);
printf("%d", n);
}get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?Answer: B
#include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;
int main ( )
{
int x = 1;
x += f1() + f2() + f3() + f2();
printf("%d", x);
return 0;
}
int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}Answer: 230
#include<stdio.h>
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);
}Answer: 140
#include<stdio.h>
int main( )
{
int i, j, k = 0;
j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k -= --j;
for(i = 0; i < 5; i++)
{
switch(i + k)
{
case 1:
case 2: printf("\n%d", i+k);
case 3: printf("\n%d", i+k);
default: printf("\n%d", i+k);
}
}
return 0;
}printf statement is executed is ____________.Answer: 10
DOSOMETHING(c, a, n)
z ← 1
for i ← 0 to k − 1
do z ← z² mod n
if c[i] = 1
then z ← (z × a) mod n
return zAnswer: 0
Answer: A
Answer: C
Answer: A
void f1(int a, int b) {
int c;
c = a; a = b; b = c;
}
void f2(int *a, int *b) {
int c;
c = *a; *a = *b; *b = c;
}
int main() {
int a = 4, b = 5, c = 6;
f1(a, b);
f2(&b, &c);
printf("%d", c - a - b);
}Answer: -5
Answer: B
| Array Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| Value | 40 | 30 | 20 | 10 | 15 | 16 | 17 | 8 | 4 |
Answer: B
int main() {
unsigned int x[4][3] =
{{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
printf("%u, %u, %u", x+3, *(x+3), *(x+2)+3);
}Answer: A
begin
q := 0
r := x
while r >= y do
begin
r := r - y
q := q + 1
end
endAnswer: B
0/200 correct0 marks