0% found this document useful (0 votes)
57 views25 pages

Qualcomm Programming Test Without Answers 2

Uploaded by

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

Qualcomm Programming Test Without Answers 2

Uploaded by

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

Qualcomm Programming Test 75 minutes

Question - 1
C Output

Consider the size of int as two bytes and size of char as one byte. Predict the output of the following code . Assume that the machine is little-endian

#include <stdio.h>
int main()
{
int a = 300;
char *b = (char *)&a;
*++b = 2;
printf("%d\n",a);
return 0;
}

300

44

556

None of the above

Question - 2
Pointers

#include<stdio.h>
void main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d\n",++*p + ++*str1-32);
}

What is the output of the following program ?

80

142

77

79

None of the above

1/25
Question - 3
Pointers

#include<stdio.h>
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("%d\n", a);
}

42

2016

None of the above

Question - 4
Pointers

#include <stdio.h>
int f(int x, int *py, int **ppz)
{
int y, z;
**ppz += 1;
z = **ppz;
*py += 2;
y = *py;
x += 3;
return x + y + z;
}
int main()
{
int c, *b, **a;
c = 4;
b = &c;
a = &b;
printf("%d\n", f(c, b, a));
return 0;
}

2/25
18

19

21

22

25

Question - 5
Logical Operators

What is the output of the following program ?

#include <stdio.h>
int main(){
int x = -1, y = 0, z = -1;
int m = -1, n = 0, o = -1;
int p = x && y && z++ || x++;
int q = m++ && ++n || o++;
printf("\n%d %d %d %d %d %d %d", x, z, p, m, n, o, q);
return 0;
}

0 -1 1 0 1 0 1

0010101

0 -1 1 0 1 0 -1

0 -1 1 0 1 -1 1

None of the above

Question - 6
Program Logic

What does the following program do ?

#include <iostream>
using namespace std;
int count(string str)
{
int n = str.length();
return n*(n+1)/2;
}

int main()
{
string s = "abcde";
cout << count(s);
return 0;
}

3/25
Counts the number of characters in the string

Counts the number of non repeating characters in the string

Counts the number of substrings in the string

It adds the ASCII values of the characters present in the string

None of the above

Question - 7
Program Logic

What does the following program do ?

#include <iostream>
using namespace std;
int token(char str[])
{
int res = 0;
for (int i=0; str[i] !='\0'; i++)
{
if (str[i] == '1')
{
for (int j=i+1; str[j] !='\0'; j++)
if (str[j] == '1')
res++;
}
}
return res;
}

int main()
{
char str[] = "0000001";
cout << token(str);
return 0;
}

Count the number of 1's in the Binary String

Modify the Binary String by replacing all 0's with 1

It sorts the Binary String by moving all 0's to one end and all 1's to the other end

It checks if the even bits in the Binary String is 1

None of the above

Question - 8
C Output

Predict the output :

#include <stdio.h>

4/25
#include <stdio.h>
int f(int n)
{
if(n <= 1)
return 1;
if(n%2 == 0)
return f(n/2);
return f(n/2) + f(n/2+1);
}

int main()
{
printf("%d", f(11));
return 0;
}

Stack Overflow

None of the above

Question - 9

#include<stdio.h>
int main(){
int num = 12345;
printf("\n%d",printf("%d",num));
printf("\n");
return 0;
}

12345 1

12345 0

Compiler Error

12345 5

None of the above

Question - 10

#include<stdio.h>

int main()
{
char *s = "Geeks Quiz";
int n = 7;
printf("%.*s", n, s);
5/25
return 0;
}

Geeks Quiz

Nothing is printed

Geeks Q

Geeks Qu

None of the above

Question - 11

#include<stdio.h>
int main(){
char c=125;
c=c+3;
printf("%d",c);
return 0;
}

-127

128

-128

None of the above

Question - 12

#include <stdio.h>
int main()
{
char arr[100];
printf("%d", scanf("%s", arr));
/* Suppose that input value given for above scanf is "GeeksQuiz" */
return 0;
}

10

100

None of the above

6/25
Question - 13

Provide the output for the program given below.

#include<stdio.h>
int main()
{
int a = 2,b = 5;
a = a^b;
b = b^a;
printf("%d %d",a,b);
return 0;
}

25

52

72

77

None of the above

Question - 14
Pre-processor

What will be output if you will compile and execute the following c code?
#include<stdio.h>
#define x 5+2
int main(){
int i;
i=x*x*x;
printf("%d",i);
return 0;
}

343

27

133

Compiler Error

None of the above

Question - 15

#include<stdio.h>
int main(){
int a=2;

7/25
if(a==2){
a=~a+2 << 1;
printf("%d",a);
}
return 0;
}

-2

-1

None of the above

Question - 16

Predict the output of the given program below :

#include <stdio.h>
int main() {
int y = 0;
int x = (~y == 1);
printf("%d", x);
return 0;
}

-1

Compiler Error because ~ is not a valid operator

None of the above

Question - 17

What is the output of the following program ?


#include <stdio.h>
int main() {
static int a = 3;
printf("%d ", a--);
if ( a )
main();
printf("\n");
}

333

321

8/25
Program will print 3 infinitely

Program will print 2 infinitely

None of the above

Question - 18

What is the output of the following program ?

#include<stdio.h>
int main()
{
int n;
for (n = 9; n!=0; n--)
printf("n = %d", n--);
return 0;
}

97531

987654321

Infinite loop

9753

Question - 19
Fill in the blanks

Fill in the blanks :

#include <stdio.h>
#include <stdlib.h>

void main() {
int c, *b, ____a, *d;
c = 4;
b = &c;
a = &b;
b = (int *)_____(sizeof(int));
*b = 2;
d = (int *)_____(b, 2*sizeof(int));
________("Answer =%d\n", c);
}

*a, malloc, calloc, scanf

*a, malloc, calloc, printf

**a, malloc, realloc, printf

**a, malloc, calloc, printf

9/25
None of the above

Question - 20
Operators

#include <stdio.h>
int main()
{
int x = 10;
int y = 20;
x += y += 10;
printf (" %d %d", x, y);
return 0;
}

30 20

40 30

20 20

10 30

None of the above

Question - 21

#include <string.h>
#include<stdio.h>
int main(){
int i;
char *str = "Hello world";
for(i=0; i<strlen(str); i++)
{
str[i] = 48 + i;
}
printf("%s\n",*str);

return 0;
}

0123456789:

0123456789

12345678910

012345678910

None of the above

Question - 22
10/25
What does the following program do when the input is unsigned 16-bit integer?

#include <stdio.h>

int main( )
{
unsigned int num;
int i;
scanf ("%u", &num);

for ( i = 0; i<16; i++)


{
printf ("%d", (num << i & 1 << 15 ) ? 1:0);
}

return 0;
}

It prints all even bits of num

It prints all odd bits of num

It prints the bits of num in the reverse order

It prints binary equivalent of num

None of the above

Question - 23

Predict the output of the program given below :

#include <stdio.h>
#include <stdlib.h>
int top=0;
int fun1()
{
char a[]= {'a','b','c','(','d'};
return a[top++];
}
int main()
{
char b[10];
char ch2;
int i = 0;
while (ch2 = fun1() != '(')
{
b[i++] = ch2;
}
printf("%s",b);
return 0;
}

abc(

abc

3 special characters with ASCII value 1

11/25
Empty String

None of the above

Question - 24

#include <stdio.h>
char str1[100];

char *fun(char str[])


{
static int i = 0;
if (*str)
{
fun(str+1);
str1[i] = *str;
i++;
}
return str1;
}

int main()
{
char str[] = "GATE CS 2015 Mock Test";
printf("%s", fun(str));
return 0;
}

What is the output of the above C program ?

GATE CS 2015 Mock Test

tseT kcoM 5102 SC ETAG

Nothing is printed on screen

Segmentation Fault

Compiler Error as the NUL character is not appended to the string

Question - 25

What is the output of the following program ?

#include <stdio.h>
int main() {
int x = 2, a = 7;
int y = 1, b = 3;
int z;
if ( x++ >= 3 && ++y <= 2 )
{
z = x - y;
}
else
{
z = x + y;

12/25
}
printf("%d ", z);
if ( a >= 5 || b-- < 3 )
{
z = a - b;
}
printf("%d\n", z);
}

54

05

44

15

None of the above

Question - 26

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 ?

12

120

120400

1034

1204

Question - 27

What is the output printed by the program below ?

#include <stdio.h>
int main() {
int x = 10;
int y = (x++, x++, x++);
printf("%d %d\n", x, y);
return 0;
}

13 12
13/25
13 13

12 12

10 10

None of the above

Question - 28
Structure Bit Fields

#include<stdio.h>
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit={1, 2, 13};
printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);
return 0;
}

1, 2, 13

1, 4, 4

-1, 2, -3

-1, -2, -13

None of the above

Question - 29
C Output

What is the output of the following program ?

#include <stdio.h>
int main() {
int x = 10;

x = x & 0x0000000C;
x = x << 3;
x = x | 0x0000000F;
x = x ^ 0x0;

printf("%d", x);
}

15

79

94

14/25
0

None of the above

Question - 30

What is the output of the program given below ?

# include<stdio.h>
# include<stdlib.h>

void fun(int *a)


{
a = (int*)malloc(sizeof(int));
}

int main()
{
int *p;
fun(p);
*p = 6;
printf("%d\n",*p);
return(0);
}

Undefined

Segmentation Fault

Compiler Error

Question - 31

What is the output of the following program ?

#include <stdio.h>
void main() {
int i = 0;
for (i=0; i<20; i++)
{
switch(i)
{
case 0: i+= 5;
case 1: i+= 2;
case 5: i+= 5;
default: i+= 4;
break;
}
printf("%d ", i);
}
}

15/25
0 5 9 13 17

1 9 13 17

12 17 22

16 21

None of the above

Question - 32
Strings

What is the output of the program below ?

#include <stdio.h>
int main(){
char c[] = "GATE2011";
char *p = c;
printf("%s\n", p + p[3] - p[1]);
return 0;
}

GATE2011

TE2011

E2011

2011

11

Question - 33

Predict the output for the program below :

#include <stdio.h>
void f (int n)
{
if (n <=1)
{
printf ("%d", n);
}
else
{
f (n/2);
printf ("%d", n%2);
}
}

int main( )
{
int n = 173;
f(n);

16/25
return 0;
}

010110101

010101101

10110101

10101101

None of the above

Question - 34

Find the output for the following program :


#include <stdio.h>
int fun(int n, int *f_p) {
int t, f;
if ( n <= 1 ) {
*f_p = 1;
return 1;
}
t = fun(n-1, f_p);
f = t+*f_p;
*f_p = t;
return f;
}
int main() {
int x = 15;
printf("%d\n", fun(5, &x));
}

14

Question - 35

What is the output of the following program ?


#include <stdio.h>
void fn (int i, char *s) {
while (i) {
s++;
i--;
}
}
int main() {
int a = 2;
17/25
static char c[] = "test";
fn(a, c);
printf("%s\n", c);
return 0;
}

test

est

st

Nothing ( Empty String )

Question - 36

What is the output of the program below when you give 66 as the input to scanf ?

#include <stdio.h>
int main(){
int n;
printf("%d", printf("%d", scanf("%d", &n) + printf("%s", "Amrita")));

return 0;
}

Amrita81

18Amrita

Amrita71

71Amrita

None of the above

Question - 37
File Handling

#include <stdio.h>
int main()
{
FILE *fpin, *fpout;
char c;
fpin = fopen("input.txt", “r");
fpout = fopen("output.txt", “w");
c= fgetc(fpin);
while ( c!= ____ )
{
fputc(___, ___);
c= fgetc(fpin);
}
return 0;

18/25
}

Fill in the blanks

Null, fpin, c

EOF, c, fpout

EOF, c, fpin

\n, c, fpout

None of the above

Question - 38

What is the output of the following program ?

#include <stdio.h>
void fun1(char *s1, char *s2) {
char *temp;
temp = s1;
s1 = s2;
s2 = temp;
}
void fun2(char **s1, char **s2) {
char *temp;
temp = *s1;
*s1 = *s2;
*s2 = temp;
}
int main() {
char *str1 = "Hi", *str2 = "Bye";
fun1(str1, str2);
printf("%s %s\n", str1, str2);
fun2(&str1, &str2);
printf("%s %s", str1, str2);
return 0;
}

Bye Hi Bye Hi

Bye Hi Hi Bye

Hi Bye Hi Bye

Hi Bye Bye Hi

None of the above

Question - 39
What is the output of the following program ?

#include <stdio.h>
#include <stdlib.h>

19/25
char *check(int a[3], int n){
int temp, i, j;
char *out;
for(i=0; i<n-1; i++){
for(j=i+1; j<n; j++){
if ( a[i] > a[j] ){
*out = '0';
return out;
}
}
}
*out = '1';
return out;
}
int main(){
int i;
int array[3] = {1, 3, 2};
char *a;

a = check(array, 3);
if ( *a == '0' ){
printf("\nList is not sorted");
}
else
{
printf("\nList is sorted");
}
}

List is sorted

List is not sorted

Compiler Error

Segmentation Fault

None of the above

Question - 40
Strings

What is the output of the program below ?

20/25
str1 is Quiz, str2 is Geeks

str1 is Geeks, str2 is Quiz

str1 is Geeks, str2 is Geeks

str1 is Quiz, str2 is Quiz

None of the above

Question - 41

Consider the C program below. The value printed by the program is ___________

#include <stdio.h>
int *A, stkTop;
int stkFunc (int opcode, int val)
{
static int size=0, stkTop=0;
switch (opcode)
{
case -1:
size = val;
break;
case 0:
if (stkTop < size ) A[stkTop++]=val;
break;
default:
if (stkTop) return A[--stkTop];
}
return -1;
}
int main()
{
int B[20];
A=B;
stkTop = -1;
stkFunc (-1, 10);
stkFunc (0, 5);
stkFunc (0, 10);
printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));
}

17

15

10

Question - 42
Union

#include <stdio.h>
union values {
21/25
unsigned char a;
unsigned char b;
unsigned int c;
};

int main() {
union values val;
val.a=1;
val.b=2;
val.c=300;
val.b=255;
printf("%d,%d,%d",val.a,val.b,val.c);
}

The output is :

255, 255, 255

255, 255, Garbage Value

255, 255, 511

255, 0, 0

None of the above

Question - 43

What is the output of the following program ?

#include <stdio.h>
union U {
int x;
char y;
};
int main() {
union U u1;
u1.x = 258;
u1.y = '0';

printf("%d %d", u1.x, u1.y);

return 0;
}

258 0

258 30

256 48

304 48

None of the above

Question - 44
22/25
#include <stdio.h>
enum days{ sun, mon, tue = 5, wed, thurs, fri, sat};
int main()
{
enum days day;
day = thurs;
printf("%d\n",day);
return 0;
}

Question - 45
Error Handling

You have executed the fopen library function to read a file. fopen returned NULL. How can you determine why fopen failed programmatically ?

Examine the return value of fopen

Go to the directory and physically check if the file exists

Examine the errno global variable

Examine the FILE pointer

Question - 46

#include <stdio.h>
void fun1(int);
void fun2(int);
void fun1 (int n) {
if (n == 0 ) return;
printf ("%d" , n);
fun2 (n - 2);
printf ("%d" , n);
}
void fun2 (int n) {
if (n == 0) return ;
printf ("%d" , n);
fun1(++n) ;
printf ("%d" , n);
}
int main()
{
fun1(5);

23/25
return 0;
}

53423122233445

53423120112233

53423122132435

53423120213243

Question - 47

#include <stdio.h>
int count = 0;
int total (int v) {
while (v) {
count += v & 1;
v >>= 1;
}
return count;
}
void main ( ) {
static int x = 0;
int i = 5;
for ( ; i > 0; i--) {
x = x + total(i);
}
printf ("%d\n", x) ;
}

12

31

23

44

Question - 48

#include <stdio.h>
#include<string.h>
void printlength (char *s, char *t) {
int len;
unsigned int c = 0;
len = (strlen(s) - strlen(t)) > c ? strlen(s):strlen(t);
printf ("%d\n", len);
}
int main ( ) {
char *x = "abc";
char *y = "defgh";
printlength (x,y);
return 0;
}

24/25
1

Question - 49

The following function computes the maximum value contained in an integer array p[ ] of size n, (n>=1).
The missing loop condition is :

a != n

b != 0

b > (a + 1)

b != a

Question - 50

The output of the following C program is _________.

-5

-4

25/25

You might also like