void func(void){ printf("func"); ((char*) 0)=0; } The function func(), triggers memory fault. Which one explains why "func" may NOT be printed before the crash? Choice 1 Insufficient information to determine why the output fails. Choice 2 printf() expects more than one argument. As only one argument is given, crash may actually occur inside printf(). Choice 3 Output stream is buffered and may not be flushed before the crash occurs. (Ans--?) Choice 4 printf() always buffers output until a newline character appears in buffer. Since no newline was present in the format string, nothing is printed.
How does variable definition differ from variable declaration? Choice 1 Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type. Choice 2 Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type. Choice 3 Variables may be defined many times, but may be declared only once.(Ans --?) Choice 4 Variable definition must precede variable declaration. Choice 5 There is no difference in C between variable declaration and variable definition.
Which one of the following is a true statement about pointers? Choice 1 Pointer arithmetic is permitted on pointers of any type.(Ans-- ??) Choice 2 A pointer of type void * can be used to directly examine or modify an object of any type. Choice 3 Standard C mandates a minimum of four levels of indirection accessible through a pointer. Choice 4 A C program knows the types of its pointers and indirectly referenced data items at runtime. Choice 5 Pointers may be used to simulate call-by-reference.
unsigned int p=0; (p^p)||p++||++p||p++; What is the value of the variable "p" after executing the above code? Choice 1 1 Choice 2 2 (Ans--??) Choice 3 3 Choice 4 The value is undefined because "p" is initialized to 0.
Which is functionally equivalent of arithmetic right shift of signed int p by 2 and is portable? Choice 1 p / 4 (Ans---??) Choice 2 p / 2 Choice 3 p >>> 2 Choice 4 p >> 2 Choice 5 p > 0 ? p >> 2 | 1 << sizeof(p) * 8 - 1 : p >> 2
char var1[10]; char var2[5]="Forum"; strcpy(var1,var2); printf("%s,%s",var1,var2); What is the output of the above code? Choice 1 No output as it is array overflow error. Choice 2 "Forum Forum" Choice 3 Results undefined. Depending on platform, code may cause access violation. Choice 4 Compilation error because string pointers can be initialized with a string literals only
If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.
I am not sure what does variable definition means but it should be some thing like defining the class.
My answer would be The null pointer is the pointer in which the value is zero (0). but then its debatable.
Re: 100 Multiple choice questions in C (New Question?) 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 );
Re: 100 Multiple choice questions in C (Ask New Questions?) 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.