Programming (C/C++)
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: 25 | |
Created by: Prabha Kade | |
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 Letter H Letter G Letter B |
int x = 0; for ( ; ; ) { if (x++ == 4) break; continue; } printf(x=%dn, x);
What will be printed when the sample code above is executed?
Which of the following variables name is NOT valid?
int i = 4; int x = 6; double z; z = x / i; printf(z=%.2fn, z);
What will print when the sample code above is executed?
int y[4] = {6, 7, 8, 9}; int ptr = y + 2; printf(%dn, ptr[ 1 ] ); /*ptr+1 == ptr[1]/
What is printed, when the sample code above is executed?
char txt [20] = Hello world!;
How many bytes are allocated by the definition above?
What are two predefined FILE pointers in C?
Which of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?
penny = one nickel = five dime = ten quarter = twenty-five
How is enum used to define the values of the American coins listed above?
int a [8] = { 0, 1, 2, 3 };
The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
According to the Standard C specification, what are the respective minimum sizes (in bytes) of the following three data types: short; int; and long?
Which of the following is a true statement about pointers?
long factorial (long x) { ???? return x * factorial(x - 1); }
With what do you replace the ???? to make the function shown above return the correct answer?
When applied to a variable, what does the unary & operator yield?
How is a variable accessed from another file?
Which one of the following is not a valid identifier?
u32 X (f32 f) { union { f32 f; u32 n; } u; u.f = f; return u.n; }
Given the function X() is defined above, assume that u32 is a type-definition indicative of a 32-bit unsigned integer and that f32 is a type-definition indicative of a 32-bit floating-point number. Which of the following describes the purpose of the function defined above?
/* Increment each integer in the array 'p' of * size 'n'. / void increment_ints (int p [/*n/], int n) { assert(p != NULL); /* Ensure that 'p' isn't a null pointer. / assert(n >= 0); / Ensure that 'n' is nonnegative. / while (n) / Loop over 'n' elements of 'p'. / { *p++; / Increment p. */ p++, n--; / Increment p, decrement n. */ } }
Consider the function increment_ints(), defined above. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?
FILE *f = fopen( fileName, "r" ); readData( f ); if( ???? ) { puts( "End of file was reached" ); }
Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?
Global variables that are declared static are ____________. Which one of the following correctly completes the sentence above?
/* sys/cdef.h / #if defined(STDC) || defined(__cplusplus) #define __P(protos) protos #else #define __P(protos) () #endif / stdio.h */ #include <sys/cdefs.h> div_t div __P((int, int));
The code above comes from header files for the FreeBSD implementation of the C library. What is the primary purpose of the __P() macro?
/* Read a double value from fp. */ double read_double (FILE * fp) { double d; assert(fp != NULL); fscanf(fp, %lf, d); return d; }
The code above contains a common error. Which one of the following describes it?
/* Read an arbitrarily long string. / int read_long_string (const char * const buf) { char * p = NULL; const char * fwd = NULL; size_t len = 0; assert(buf); do { p = realloc(p, len += 256); if (!p) return 0; if (!fwd) fwd = p; else fwd = strchr(p, ' '); } while (fgets(fwd, 256, stdin)); *buf = p; return 1; }
The function read_long_string(), defined above, contains an error that may be particularly visible under heavy stress. Which one of the following describes it?
According to Standard C, what is the type of an unsuffixed floating-point literal, such as 123.45?
Which one of the following is true for identifiers that begin with an underscore?
Which one of the following is not a valid C identifier?