C-Programing Test-2 (Moderate)
C-Programing Test-2 (Moderate)
Branch : CS & IT
Maximum Marks: 26
{ #include<stdio.h>
switch(i) { {
} while(*cptr != '\0')
printf("%d",i++); {
return 0; cptr++;
} }
return 0; {
} FILE *fp;
int main() (C) The given program converts the small case
letters to the uppercase letters
{
(D) None of these
pa1=&a1;
Q13. (2 Marks) [Numerical Answer Type] What is
a1.s1.c='1'; the output of the following C code?
} int v1 = 2;
Options: int v2 = 1;
(A) pa1->s1.c
while (n > 0) {
(B) pa1.s1.c
(C) a1->s1.c if (n % 2 == 1)
(D) All of the above
v2 = v1 * v2;
Q12. (2 Marks) What is the output of the
v1 = v1 * v1;
following C code?
n = n / 2;
#include <stdio.h>
}
int main(void) {
return v2;
int c;
}
for ( ; ; ) {
int main()
c = getchar();
{
if (c == EOF) break;
printf("%d", mystery(10));
if ((c >= 97) && (c < 123))
return 0;
c -= 32;
}
putchar(c);
Answer: __________
}
Q14. (2 Marks) [Numerical Answer Type] What is
return 0;
the output of the following C code?
}
#include<stdio.h>
Options:
int func(int p)
(A) The given program checks the ASCII is
between 97 and 123 {
(B) The given program checks the size of the file
static int r;
5
return 1; p+=1;
{ return 0;
r = p; }
} print(max(x++,y),x,y);
Options: return 0;
(A) 2 2
}
(B) 4 2
(C) 4 4 Options:
(D) 2 4 (A) 2 2 2
(B) 3 3 2
Q17. (2 Marks) Find the output of the following C
(C) 3 2 3
program:
(D) Compilation Error
#include<stdio.h>
int main() {
c = b;
++c;
printf("%s", *(*(c)+1));
Options:
(A) GATE
(B) Arpit
(C) it
(D) 026
#include<stdio.h>
int main()
• cptr increments until \0, then cptr - • k=++b[1]: b[1] becomes 2 → k=2.
name = address difference = 5. • i=b[1]++: i=2, then b[1] becomes 3.
4. Answer: (B) 0 2 • m=b[k++]: m=b[2]=32, then k increments
• --a decrements a to 0 (false). to 3.
• Logical AND (&&) short-circuits: b-- is not 10. Answer: (B) Creates file with "Hello"
evaluated. • fopen("abc.c", 'w') creates the file if it
• else prints a=0, b=2 (unchanged). doesn’t exist.
15. Answer: (A) (12345) (ABCDE) o x++ (1) < 2 → returns y=2,
then x increments to 2.
• strcpy(s, "12345-") → s = "12345-".
• print(2, 2, 2) prints "2 2 2".
• strcat(p, "ABCDE") → s = "12345-ABCDE".
• p += 6 points to 'A'.