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?
|
||||||||||
With
every use of a memory allocation function, what function should be used to
release allocated memory, which is no longer needed?
|
|||||||||||
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);
}
|
|||||||||||
How
many union members can be initialized?
|
|||||||||||
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?
|
|||||||||||
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?
|
|||||||||||
What
is the difference between a declaration and a definition of a variable?
|
|||||||||||
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?
|
|||||||||||
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?
|
|||||||||||
"My
salary was increased by 15%!"
Select the statement, which will EXACTLY reproduce the line of text above.
|
Answers
121.
|
Answer
: (c)
Reason: the expression is evaluated and the value of
z is 10
|
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
|
|
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
|
|
Answer
: (a)
Reason: only one member of a union at any one time
can be initialized
|
|
Answer
: (d)
Reason:
|
|
Answer
: (e)
Reason: syntax error because break can’t be used
with selection control structures, but can used with repetitive, or select
control structure.
|
|
Answer
: (d)
Reason: Difference between a declaration and a
definition is a declaration occurs once, but a definition may occurs many
times.
|
|
Answer
: (e)
Reason: testarray is a three dimensional array the
element of a three dimensional array of testarray[2][1][0] is 11
|
|
Answer
: (e)
Reason: the output of the program is 22,13,13,13
|
|
Answer
: (d)
Reason: the correct printf statement for "My
salary was increased by 15%!" is printf ("\"My salary was
increased by 15%%!\"\n");
|
Can I ahave all in one both Java and C++.Please
ReplyDelete