0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
void crash(void){
printf("got there");
((char*) 0)=0;

}
The function crash(), defined above, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
Choice 1

There is insufficient information to determine why the output fails to appear. A broader context is required.
Choice 2

printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.
Choice 3

If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs. (Ans--?)
Choice 4

printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.
If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
What is a variable DECLARATION (as opposed to a variable definition)?
Choice 1

The assignment of properties and an identifier (a name) to a variable (Ans---?)
Choice 2

The assignment of storage space to a variable
Choice 3

The assignment of properties and storage space to a variable
I am not sure what does variable definition means but it should be some thing like defining the class.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
Which one of the following constitutes a true statement about the null pointer?
Choice 1

The null pointer is a pointer to a string of zero (0) width; that is, it is a pointer to the NUL character.
Choice 2

The null pointer is the pointer in which the value is zero (0).
Choice 3

The null pointer is any uninitialized pointer.
Choice 4

The null pointer is the pointer in which the value is the value of a constant defined several places throughout the standard library. ()
Choice 5

The null pointer is known to point to no object and is represented in C expressions by a pointer-typed zero (0). (Ans--?)
My answer would be The null pointer is the pointer in which the value is zero (0). but then its debatable.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
unsigned int x=0;
(x^x)||x++||++x||x++;

What is the value of "x" after the execution of the above sample code?
Choice 1

1
Choice 2

2 (Ans--??)
Choice 3

3
Choice 4

The value is undefined because "x" is initialized to 0.
Check with your compiler
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
A right shift is arithmetic if it propagates the sign bit of its principal operand. The C standard grants compiler writers the freedom to determine whether or not right shifts should be arithmetic. Given the definition above, which one of the following is functionally equivalent to an arithmetic right shift of signed int x by two (2) and is guaranteed to be portable?
Choice 1

x / 4 (Ans---??)
Choice 2

x / 2
Choice 3

x >>> 2
Choice 4

x >> 2
Choice 5

x > 0 ? x >> 2 | 1 << sizeof(x) * 8 - 1 : x >> 2
x / 4
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by MultipleChoiceInC
char var1[10];
char var2[5]="hello";
strcpy(var1,var2);
printf("%s,%s",var1,var2);

What does the above code print?
Choice 1

Nothing, the link fails with an array overflow error.
Choice 2

"Hello Hello"
Choice 3

It is unknown; the results are undefined, and depending on the platform, the code may cause an access violation or core dump.
Choice 4

Nothing, the compilation fails, because only string pointers can be initialized with a string literal.
Choice 5

Nothing, the program fails with an "array overflow" runtime error message before printing anything.
"Hello Hello"
but there should be a comma (,) in between both the hello's
0
psapikas's Avatar
Light Poster
Quote:
Originally Posted by shabbir
"Hello Hello"
but there should be a comma (,) in between both the hello's
I think this result should be printed if the second array was defined as: var2[6]
0
brajrajsingh's Avatar, Join Date: Jan 2008
Light Poster
Also Please mail the answers to brajrajsingh@gmail.com
0
MultipleChoiceInC's Avatar
Go4Expert Member
char buf[50]="Hello World";
char *ptr=buf+5;

What's the right way to copy 15 bytes from the location pointed by "ptr" to the beginning of "buf"?
Choice 1
memmove( buf, ptr, 15 ); (ans)

Choice 2
Illegal memory access because it will read memory past the end of the string.

Choice 3
strncpy( buf, ptr, 15 );

Choice 4
Cannot be done because the source and destination overlap.

Choice 5
memcpy( buf, ptr, 15 );
0
MultipleChoiceInC's Avatar
Go4Expert Member
struct node {
int id;
int lengh;
struct node *next;
struct node *prev;
unsighed char data[1];
}

Considering struct node, an aggregate type defined above, which one of the following might explain the declaration of its peculiar member data?
Choice 1

There is no difference between character unsigned char data and array unsigned char data [1] since each allocates only a single byte. Identical operations can be performed on both quantities. The choice was one of preference.
Choice 2

The programmer is declaring a bit field called data, which consists of only a single bit. struct node probably represents some hardware device.
Choice 3

data is probably used in conjunction with length and malloc() to create objects of variable size. struct node is essentially a header for an object of indeterminate size.
Choice 4

The information provided by the definition of struct node is insufficient to formulate a guess about the purpose of the member data or its strange declaration. (Ans)
Choice 5

The programmer has made a typo. If the programmer had intended to allocate only a single byte, the data would have been declared as unsigned char data instead.