C Programming and Problem Solving Questions and Answers 121 to 130

C Programming and Problem Solving

Questions 121 to 130



121.
int z,x=5,y=-10,a=4,b=2;
z = x++ - --y * b / a;
What number will z in the sample code above contain?
(a)
5
(b)
6
(c)
10
(d)
11
(e)
12.
122.
With every use of a memory allocation function, what function should be used to release allocated memory, which is no longer needed?
(a)
unalloc()
(b)
dropmem()
(c)
dealloc()
(d)
release()
(e)
free().
123.
What is the correct output of the following program?
#include <string.h>
       void main()
      {
        char str[] = “ISIT”, rev[5];
        int i = strlen(str), j=0;
        for(;i>=0;rev[i++] = str[i--]);
        rev[j]=’\0’;
        puts(rev);
      }
(a)
Syntax error
(b)
ISIT
(c)
Nothing
(d)
ITSI
(e)
TIIS.
124.
How many union members can be initialized?
(a)
Only one member of a union at any one time
(b)
Any number of members of a union at one time
(c)
Union members can not be initialized
(d)
Only two members of a union at any one time
(e)
Only two members of a union at any time.
125.
char* myFunc (char *ptr)
{
ptr += 3;
return (ptr);
}
int main()
{
char *x, *y;
x = "HELLO";
y = myFunc (x);
printf ("y = %s \n", y);
return 0;
}
What will print when the sample code above is executed?
(a)
y = HELLO
(b)
y = ELLO
(c)
y = LLO
(d)
y = LO
(e)
x = O.
126.
Consider the following code:
 void main()
{
int a[5] = {6,8,3,9,0}, i=0;
if (i != 0)
{
 break;
printf(“%d”, a[i]);
}
else
printf(“%d”, a[i++]);
}
What is the output of the above program?
(a)
6
(b)
8
(c)
Runtime error
(d)
No output
(e)
Syntax error.
127.
What is the difference between a declaration and a definition of a variable?
(a)
Both can occur multiple times, but a declaration must occur first
(b)
There is no difference between them
(c)
A definition occurs once, but a declaration may occur many times
(d)
A declaration occurs once, but a definition may occur many times
(e)
Both can occur multiple times, but a definition must occur first.
128.
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
(a)
3
(b)
5
(c)
7
(d)
9
(e)
11.
129.
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed?
(a)
12,10,11,13
(b)
22,10,11,13
(c)
22,11,11,11
(d)
12,11,11,11
(e)
22,13,13,13.
130.
"My salary was increased by 15%!"
Select the statement, which will EXACTLY reproduce the line of text above.
(a)
printf("\"My salary was increased by 15/%\!\"\n");
(b)
printf("My salary was increased by 15%!\n");
(c)
printf("My salary was increased by 15'%'!\n");
(d)
printf("\"My salary was increased by 15%%!\"\n");
(e)
printf("\"My salary was increased by 15'%'!\"\n");.

Answers


121.
Answer : (c)
Reason:  the expression is evaluated and the value of z is 10
122.
Answer : (e)
Reason:  With every use of a memory allocation function, what function should be used to release allocated memory, which is no longer needed is free
123.
Answer : (c)
Reason:  Because the statement int i = strlen (str); stores the value 5 in i which is null ‘\0’ chareacter and hence when we run the for loop its first sotres str[i] in rev[j] . so once we printf the output statement puts (rev); terminates because of null value a 0th location of string rev. Hence option (c) is the answer
124.
Answer : (a)
Reason:  only one member of a union at any one time can be initialized
125.
Answer : (d)
Reason: 
126.
Answer : (e)
Reason:  syntax error because break can’t be used with selection control structures, but can used with repetitive, or select control structure.
127.
Answer : (d)
Reason:  Difference between a declaration and a definition is a declaration occurs once, but a definition may occurs many times.
128.
Answer : (e)
Reason:  testarray is a three dimensional array the element of a three dimensional array of testarray[2][1][0] is 11
129.
Answer : (e)
Reason:  the output of the program is 22,13,13,13
130.
Answer : (d)
Reason:  the correct printf statement for "My salary was increased by 15%!" is printf ("\"My salary was increased by 15%%!\"\n");


<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


1 comment :