0% found this document useful (0 votes)
98 views

Programming Proficiency Key

sdafd

Uploaded by

Dr.Sumithra A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Programming Proficiency Key

sdafd

Uploaded by

Dr.Sumithra A
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Programming Proficiency in C

N V Shibu (AP/CSE), J Adri Jovin (AP/IT)


Sri Ramakrishna Institute of Technology Date: September 16, 2019

Level 1
1. Data Types
Which of the following is not a valid declaration in C?
1. short int x
2. short x
3. signed short x
4. unsigned short x

(a) 1 and 3
(b) 1
(c) All are valid X
(d) 3 and 4

2. Data Types
Predict the output:
#include <stdio.h>
int main()
{
float c = 5.0;
printf (”Temperature in Fahrenheit is %.2f”, (9/5)*c + 32);
return 0;
}

(a) 42.0
(b) 37.0 X
(c) Compiler Error
(d) 42

3. Data Types
What is the data type of the constant value 1.414?

(a) int
(b) double X
(c) float
(d) long

4. Operators
Predict the output of the following code
#include<stdio.h>

1
int main()
{
int x, y = 5, z = 5;
x = y == z;
printf(”%d”, x);
return 0;
}
(a) 0
(b) Compiler Error
(c) 1 X
(d) 5
5. Operators
Predict the output of the following code
#include<stdio.h>
int main()
{
int a = 3,b=2,c=0;
c=a++ + ++b;
printf(”%d”,c);
return 0;
}
(a) 5
(b) 6 X
(c) 7
(d) lvalue required
6. Input/Output
In the context of the following printf() in C, pick the best statement.
i) printf(”%d”,8);
ii) printf(”%d”,090);
iii) printf(”%d”,00200);
iv) printf(”%d”,0007000);

(a) Only i) would compile. And it will print 8.


(b) Both i) and ii) would compile. i) will print 8 while ii) will print 90
(c) All i), ii), iii) and iv) would compile successfully and they will print 8, 90, 200 &
7000 respectively.
(d) Only i), iii) and iv) would compile successfully. They will print 8, 128 and 3584
respectively. X

7. Loop
Predict the output of the following code
#include<stdio.h>

2
int main()
{
static int var = 5;
printf(”%d ”,var–);
if(var)
main();
}

(a) Infinite loop


(b) Compilation Error
(c) 543210
(d) 54321 X

8. Operators
Predict the output of the following code
#include<stdio.h>
int main()
{
int i=10;
i=!i>5;
printf(”i=%d”,i);
}

(a) 0 X
(b) 10
(c) 5
(d) 1

9. Loop
Predict the output of the following code
#include<stdio.h>
int main()
{
int i = 0;
switch (i)
{
case ’0’: printf(”SRIT”);
break;
case ’1’: printf(”Quiz”);
break;
default: printf(”SRITQuiz”);
}
return 0;
}

(a) SRITQuiz X

3
(b) SRIT
(c) Quiz
(d) Compile-time Error

10. Loop
Predict the output of the following code
#include<stdio.h>
int main()
{
int n;
for (n=9;n!=0;n–)
printf(“n = %d”, n–);
return 0;
}

(a) 987654321
(b) 987654321
(c) 97531
(d) Infinite loop X

4
Programming Proficiency in C
N V Shibu (AP/CSE), J Adri Jovin (AP/IT)
Sri Ramakrishna Institute of Technology Date: September 16, 2019

Level 2
1. Operators
Predict the output:
#include <stdio.h>
int main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++——l++;
printf(”%d %d %d %d %d”,i,j,k,l,m);
return 0;
}

(a) 0 0 1 3 1 X
(b) 0 0 2 3 1
(c) 0 0 1 2 1
(d) 0 0 0 1 3

2. Strings
Predict the output:
#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=9,n2=10
(b) n1=9,n2=9
(c) n1=10,n2=9 X
(d) n1=10,n2=10

3. Strings
Predict the output:
#include <stdio.h>
int main()
{

1
int i,j;
for (i=0, j=5; i¡5, j¡20; i++, j++);
printf(”i=%d j=%d”,i,j)
return 0;
}

(a) i=5,j=5
(b) i=0,j=5
(c) i=5,j=20
(d) i=15,j=20 X

4. Strings
Predict the output:
#include <stdio.h>
int fun(char *str1)
{
char *str2 = str1;
while(*++str1);
return (str1-str2);
}
int main()
{
char *str = ”SritsQuiz”;
printf(”%d”,fun(str));
return 0;
}

(a) 9 X
(b) 10
(c) 8
(d) Random Number

5. Pointers
Predict the output:
#include <stdio.h>
int main()
{
int num=50, *temp, total=0;
temp = &num;
*temp = 200;
temp=&total;
*temp=num;
printf(” %d %d %d ”, num,*temp,total);
}

(a) 50,200,50

2
(b) 50,50,50
(c) 200,200,200 X
(d) 50,200,200

6. Pointers
Predict the output:ASCII value of ’A’ is 65
#include <stdio.h>
int main()
{
char s[]={’a’,’b’,’c’,’A’,’c’,’B’};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf(”%d”,++*p + ++*str1-32);
}

(a) 132 X
(b) 52
(c) 70
(d) 98

7. Macro
Predict the output:
#include <stdio.h>
#define square(x)x*x
int main()
{
int i;
i = 64/square(4);
printf(”%d”,i);
}

(a) 16
(b) 1
(c) 64 X
(d) Division by zero

8. Pointers
Predict the output:
#include <stdio.h>
int main()
{
char *str1=”abcd”;
char str2[]=”abcd”;

3
printf(”%d %d %d”,sizeof(str1),sizeof(str2),sizeof(”abcd”));
}

(a) 3 6 5
(b) 2 6 6
(c) 2 5 5 X
(d) 2 5 6

9. Pointers
Predict the output:
#include <stdio.h>
int oned[]={1,2,3};
int main()
{
int *ptr;
ptr=oned;
ptr+=3;
printf(”%d”,*ptr);
}

(a) Compilation Error


(b) Garbage Value X
(c) 3
(d) 2

10. Operators
Predict the output:
#include <stdio.h>
int main()
{
int i=abc(10);
printf(”%d”,–i);
}
int abc(int i)
{
return(i++);
}

(a) 10
(b) 11
(c) 8 X
(d) 9

You might also like