0% found this document useful (0 votes)
230 views8 pages

Amcat Analysis

The document contains 16 coding questions related to C programming concepts like arrays, strings, pointers, memory allocation etc. Each question is followed by 4 multiple choice options for the output of the given code snippet.

Uploaded by

Sobhan Dasari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views8 pages

Amcat Analysis

The document contains 16 coding questions related to C programming concepts like arrays, strings, pointers, memory allocation etc. Each question is followed by 4 multiple choice options for the output of the given code snippet.

Uploaded by

Sobhan Dasari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

char c[] = "GEEK2018";


char *p =c;
printf("%c,%c", *p,*(p+p[3]-p[1]));
(A) G, 1
(B) G, K
(C) GEEK2018
(D) None of the above

2. char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length — i];
printf("%s",p);
(A) gnirts
(B) gnirt
(C) string
(D) no output is printed

3. char c[] = "GATE2011";


char *p =c;
printf("%s", p + p[3] - p[1]) ;
(A) GATE2011
(B) E2011
(C) 2011
(D) 011
4. int main()
{
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
(A) 1 followed by four garbage values:
(B) 1 0 0 0 0
(C) 1 1 1 1 1
(D) 0 0 0 0 0

5. int main()
{
int a[][] = {{1,2},{3,4}};
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
return 0;
}
(A) 1 2 3 4
(B) Compiler Error in line ” int a[][] = {{1,2},{3,4}};”
(C) 4 garbage values
(D) 4 3 2 1
6. char a[100][100];
Assuming that the main memory is byte-addressable and that
the array is stored starting from memory address 0, the address
of a[40][50] is: (GATE CS 2002)
(A) 4040
(B) 4050
(C) 5040
(C) 5050
Hint: base adrress+i*c*element_size+j*element size

7. # include <stdio.h>

void print(int arr[])


{
int n = sizeof(arr)/sizeof(arr[0]);
int i;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
}

int main()
{
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
print(arr);
return 0;
}
(A) 1, 2, 3, 4, 5, 6, 7, 8
(B) Compiler Error
(C) 1 2
(D) Run Time Error
8. int main()
{
int i;
int arr[5] = {0};
for (i = 0; i <= 5; i++)
printf("%d ", arr[i]);
return 0;
}
(A) Compiler Error: Array index out of bound.
(B) The always prints 0 five times followed by garbage value
(C) The program always crashes.
(D) The program may print 0 five times followed by garbage
value, or may crash if address (arr+5) is invalid.

9. #include<stdio.h>
int main()
{
int a[10][20][30] = {0};
a[5][2][1] = 2;
return 0;
}
Which of the following will print the value 2 for the above
code?
(A) printf(“%d”,*(((a+5)+2)+1));
(B) printf(“%d”,***((a+5)+2)+1);
(C) printf(“%d”,*(*(*(a+5)+2)+1));
(D) None of these
10. # include <stdio.h>

int main()
{
char str1[] = "GeeksQuiz";
char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'};
int n1 = sizeof(str1)/sizeof(str1[0]);
int n2 = sizeof(str2)/sizeof(str2[0]);
printf("n1 = %d, n2 = %d", n1, n2);
return 0;
}

A n1 = 10, n2 = 9
B n1 = 10, n2 = 10
C n1 = 9, n2 = 9
D n1 = 9, n2 = 10

11. void swap(char *str1, char *str2)


{
char *temp = str1;
str1 = str2;
str2 = temp;
}

int main()
{
char *str1 = "Geeks";
char *str2 = "Quiz";
swap(str1, str2);
printf("str1 is %s, str2 is %s", str1, str2);
return 0;
}
A str1 is Quiz, str2 is Geeks
B str1 is Geeks, str2 is Quiz
C str1 is Geeks, str2 is Geeks
D str1 is Quiz, str2 is Quiz

12. int fun(char *str1)


{
char *str2 = str1;
while(*++str1);
return (str1-str2);
}

int main()
{
char *str = "GeeksQuiz";
printf("%d", fun(str));
return 0;
}
(A) 10
(B) 9
(C) 8
(D) Random Number

13. #include<stdio.h>
int main()
{
char str[] = "GeeksQuiz";
printf("%s %s %s\n", &str[5], &5[str], str+5);
printf("%c %c %c\n", *(str+6), str[6], 6[str]);
return 0;
}
(A) Runtime Error
(B) Compiler Error
(C) uiz uiz uiz
uuu
(D) Quiz Quiz Quiz
uuu

14. int main()


{
char str[] = "%d %c", arr[] = "GeeksQuiz";
printf(str, 0[arr], 2[arr + 3]);
return 0;
}
(A) G Q
(B) 71 81
(C) 71 Q
(D) Compile-time error

15. #include <stdio.h>


int fun(char *p)
{
if (p == NULL || *p == '\0') return 0;
int current = 1, i = 1;
while (*(p+current))
{
if (p[current] != p[current-1])
{
p[i] = p[current];
i++;
}
current++;
}
*(p+i)='\0';
return i;
}

int main()
{
char str[] = "geeksskeeg";
fun(str);
puts(str);
return 0;
}

16. int main()


{
char p[] = "geeksquiz";
char t;
int i, j;
for(i=0,j=strlen(p); i<j; i++)
{
t = p[i];
p[i] = p[j-i];
p[j-i] = t;
}
printf("%s", p);
return 0;
}
Output?
(A) ziuqskeeg
(B) Nothing is printed on the screen
(C) geeksquiz

(D) gggggggg

You might also like