0

Programming

Description: Test your C skill in programming language for campus placements for bca, mca, b.sc IT, M.Sc. IT by free online preparation and practice paper tests
Number of Questions: 23
Created by:
Tags: Basics C Skills Advanced C Skills C Skills Test Java Skill Test DBMS Oracle PHP Computer Application Placement Papers MCA Entrance BCA BSC Programming Fundamentals of Computer Programming Letter E Antonyms Synonyms LCM/HCF
Attempted 0/23 Correct 0 Score 0

char *ptr; char myString[] = abcdefg; ptr = myString; ptr += 5;
What string does ptr point to in the sample code above?

  1. fg

  2. efg

  3. defg

  4. cdefg

  5. None of the above


Correct Option: A

int x = 3; if( x == 2 ) x = 0; if( x == 3 ) x++; else x += 2;
What value will x contain when the above sample code is executed?

  1. 1

  2. 2

  3. 3

  4. 4

  5. 5


Correct Option: A

Which of the following will declare a pointer to an integer at address 0x200 in memory?

  1. int *x; *x = 0x200;

  2. int *x = &0x200;

  3. int *x = *0x200;

  4. int *x = 0x200;

  5. int *x( &0x200 );


Correct Option: A

x = 3, counter = 0; while ((x-1)) { ++counter; x--; } Referring to the sample code above, what will be the value of variable counter after the execution of the code?

  1. 0

  2. 1

  3. 2

  4. 3

  5. 4


Correct Option: C

char ** array [12][12][12]; Consider array, defined above. Which of the following definitions and initializations of p is valid?

  1. char ** (* p) [12][12] = array;

  2. char ***** p = array;

  3. char * (* p) [12][12][12] = array;

  4. const char ** p [12][12][12] = array;

  5. char (** p) [12][12] = array;


Correct Option: A

double x = -3.5, y = 3.5; printf( "%.0f : %.0f", ceil( x ), ceil( y ) ); printf( "%.0f : %.0f", floor( x ), floor( y ) );
What will the above code print when it is executed? ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3

    • 3 : 4 - 4 : 3
    • 4 : 4 - 3 : 3
    • 4 : 4 - 3 : 3
    • 4 : 3 - 3 : 4
    • 3 : 3 - 4 : 4

Correct Option: A

int x = 5; int y = 2; char op = ''; switch (op) { default : x += 1; case '+' : x += y; /*It will go to all the cases/ case '-' : x -= y; } After the sample code above is executed, what will be the value of variable x?

  1. 4

  2. 5

  3. 6

  4. 7

  5. 8


Correct Option: C

Which of the following functions returns the string representation from a pointer to a time t value?

  1. Localtime

  2. Gmtime

  3. Strtime

  4. Asctime

  5. Ctime


Correct Option: D

short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} }; printf(%dn, sizeof( testarray)); Assuming a short is two bytes long, what will be printed by the above code?

  1. It will not compile because not enough initializers are given.

  2. 6

  3. 7

  4. 12

  5. 24


Correct Option: E

struct customer *ptr = malloc( sizeof( struct customer ) ); Given the sample allocation for the pointer ptr found above, which of the following statements is used to reallocate ptr to be an array of 10 elements?

  1. ptr = realloc( ptr, 10 * sizeof( struct customer));

  2. realloc( ptr, 9 * sizeof( struct customer ) );

  3. ptr += malloc( 9 * sizeof( struct customer ) );

  4. ptr = realloc( ptr, 9 * sizeof( struct customer ) );

  5. realloc( ptr, 10 * sizeof( struct customer ) );


Correct Option: A

Which of the following is a true statement about pointers?

  1. Pointer arithmetic is permitted on pointers of any type.

  2. A pointer of type void * can be used to directly examine or modify an object of any type.

  3. Standard C mandates a minimum of four levels of indirection accessible through a pointer.

  4. A C program knows the types of its pointers and indirectly referenced data items at runtime.

  5. Pointers may be used to simulate call-by-reference.


Correct Option: E

void (*signal(int sig, void (*handler) (int))) (int); Which of the following definitions of sighandler_t allows the above declaration to be rewritten as follows? sighandler_t signal (int sig, sighandler_t handler);

  1. typedef void (*sighandler_t) (int);

  2. typedef sighandler_t void (*) (int);

  3. typedef void *sighandler_t (int);

  4. #define sighandler_t(x) void (*x) (int)

  5. #define sighandler_t void (*) (int)


Correct Option: A

In a C expression, how is a logical AND represented?

  1. @@

  2. ||

  3. AND

  4. &&

  5. OR


Correct Option: D
Explanation:

Correct Answer: &&

Which of the following Standard C functions can be used to reset end-of-file and error conditions on an open stream?

  1. clearerr()

  2. fseek()

  3. ferror()

  4. feof()

  5. setvbuf()


Correct Option: A

char buf [] = Hello world!; char * buf = Hello world!; In terms of code generation, how do the two definitions of buf, both presented above, differ?

  1. The first definition certainly allows the contents of buf to be safely modified at runtime while the second definition does not.

  2. The first definition is not suitable for usage as an argument to a function call but the second definition is.

  3. The first definition is not legal because it does not indicate the size of the array to be allocated while the second definition is legal.

  4. They do not differ -- they are functionally equivalent.

  5. The first definition does not allocate enough space for a terminating NUL-character, nor does it append one while the second definition does.


Correct Option: D

Which of the following will read a character from the keyboard and store it in the variable c?

  1. c = getc();

  2. getc( &c );

  3. c = getchar( stdin );

  4. getchar( &c )

  5. c = getchar();


Correct Option: E

How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?

  1. %e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation.

  2. %e expects a corresponding argument of type double; %f expects a corresponding argument of type float.

  3. %e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.

  4. %e displays an argument of type double with trailing zeros; %f never displays trailing zeros.

  5. %e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.


Correct Option: A

Which of the following C operators is right associative?

  1. =

  2. ,

  3. []

  4. ^

  5. ->


Correct Option: A

char ptr1[] = "Hello World"; char *ptr2 = malloc( 5 ); ptr2 = ptr1; What is wrong with the above code (assuming the call to malloc does not fail)?

  1. There will be a memory overwrite.

  2. There will be a memory leak.

  3. There will be a segmentation fault.

  4. Not enough space is allocated by the malloc.

  5. It will not compile.


Correct Option: A

What does the auto specifier do?

  1. It automatically initializes a variable to 0.

  2. It indicates that a variable's memory will automatically be preserved.

  3. It automatically increments the variable when used.

  4. It automatically initializes a variable to NULL.

  5. It indicates that a variable's memory space is allocated upon entry into the block.


Correct Option: B

#include <stdio.h> int i; void increment( int i ) { i++; } int main() { for( i = 0; i < 10; increment( i ) ) { } printf(i=%dn, i); return 0; }
What will happen when the program above is compiled and executed?

  1. It will not compile.

  2. It will print out: i=9.

  3. It will print out: i=10.

  4. It will print out: i=11.

  5. It will loop indefinitely


Correct Option: E

How do you include a system header file called sysheader.h in a C source file?

  1. #include <sysheader.h>

  2. #incl "sysheader.h"

  3. #includefile <sysheader>

  4. #include sysheader.h

  5. #incl <sysheader.h>


Correct Option: A

Which one of the following printf() format specifiers indicates to print a double value in decimal notation, left aligned in a 30-character field, to four (4) digits of precision?

  1. %- 30.4e

  2. %4.30e

  3. %-4.30f

  4. %-30.4f

  5. %#30.4f


Correct Option: D
- Hide questions