Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   100 Multiple choice questions in C (http://www.go4expert.com/articles/100-multiple-choice-questions-c-t1373/)

MultipleChoiceInC 22May2008 03:18

Re: 100 Multiple choice questions in C(New Question?)
 
Which one of the following Standard C functions can be used to sort a string array?
Choice 1

qsort (Ans)
Choice 2

sort
Choice 3

quicksort
Choice 4

asort
Choice 5

There is no Standard C function for such a sort.

MultipleChoiceInC 22May2008 03:20

Re: 100 Multiple choice questions in C
 
int a[100];
int *p=a;

for(;a<p+100; a++)
*a=0;

a=p;

Which one of the following describes the error in the sample code above?
Choice 1

The initialization of p from a is not allowed since the compiler believes that they have differing types. There should be whitespace between the star and p to achieve the desired effect.
Choice 2

It is not permissible to omit the initializer of a for loop.
Choice 3

The address of the first element not in the array a is p + 100 * sizeof(int), not p + 100.
Choice 4

It is not permissible to alter the value of a. (Ans)
Choice 5

The iterator of the for loop should be a += sizeof(int) instead of a++.

MultipleChoiceInC 22May2008 05:20

Re: 100 Multiple choice questions in C(New Q?)
 
#include <stdlib.h>

int main()
{
struct x {double d; int i; char c;};

struct x *xp=(struct x*)calloc(1, sizeof(struct x));

}

Referring to the above sample code, what are the values of the structure members pointed to by "xp" after the "calloc"?
Choice 1

undefined,undefined,undefined
Choice 2

1.0,1,'\01'
Choice 3

undefined,0,'\0' (Ans)
Choice 4

0.0,0,'\0'
Choice 5

0e0,0,'\0'

madlex 7Jun2008 06:52

Re: 100 Multiple choice questions in C
 
Quote:

Originally Posted by shabbir
By definition, an lvalue is the storage space indirectly referenced by a pointer.

I am not that sure that is the answer.
By definition an lvalue is a "value" that can take part in an assigment on the left side. More particular, the lvalue is a "writable" value, and an rvalue is a "readable" value. Nothing to do with pointers.
for example:
(1+2) its a rvalue -> we could never write (1+2) = 4 :P
but this is a lvalue but also a rvalue
int & something()
{
static int something = 0;
return something;
}
something() = 3; // something() as lvalue
int some_thing = something(); // something() as rvalue

shabbir 7Jun2008 10:18

Re: 100 Multiple choice questions in C
 
So it means indirectly referenced by pointer. Your example of something also does the same.

madlex 7Jun2008 19:45

Re: 100 Multiple choice questions in C
 
Code:

//  Oki, but what pointer reference do we have here?
const int anything = 12;
int some_thing = anything;
some_thing = 0; // lvalue = rvalue
// Consider that we can use a pointer to point to an rvalue also
const char * pszSomething = "Hello";
// Considering the statement above, what would be the difference between rvalue and lvalue
// if this is the definition of an lvalue?!

That's why I think the choice "All lvalues can be used on the right side of an assignment statement. (Ans--?)" was marked as the answer, because is the most plausible of all. This means that If a value is a lvalue it can also be used as an rvalue.

And about the function int & something(); I used in the previous example,I should say that not all the references are "translated" by the compiler into pointers.In this case, it should not. But that's debatable depending on what do you mean by "pointer".

If I am wrong correct me please.
Cheers

Samdani 23Jun2008 20:28

Re: 100 Multiple choice questions in C
 
pls can anyone send me the answers at samdanikalpesh@gmail.com

XXxxImmortalxxXX 7Jul2008 13:24

Re: 100 Multiple choice questions in C
 
mate your not allowed to advertise on this forum like that

amit8_j 8Dec2008 12:05

Re: 100 Multiple choice questions in C
 
Please send me the answers to these questions at my ID amit8.j@tcs.com
Thanks
Amit

guneet 17Mar2009 13:04

Re: 100 Multiple choice questions in C !!i need answers!!
 
wud u plz send me answers for these 100 mcqs at the undersigned-as soon as possible!!
guneet2027@gmail.com


All times are GMT +5.5. The time now is 10:09.