C examn
Question 11 pts
What does the following code print: unsigned int x = -1; int y = !-0; if (x == y) printf("same"); else printf("not same");
Flag this Question
Question 21 pts
Which of the following is not a valid declaration in C? 1. short int x; 2. signed short x; 3. short x; 4. unsigned short x;
Flag this Question
Question 31 pts
What does the following lines of code print: int const a = 5; a++; printf(%d,a);
| compiler error: increment of read-only variable 'a' |
| Linker error: increment of read-only variable 'a' |
Flag this Question
Question 41 pts
Choose the correct option for the following program: int *p, **q; printf("%u ", sizeof(p)); printf("%u ", sizeof(q));
| Both the printf() will print the same value. |
| First printf() prints the value less than the second. |
| Second printf() prints the value less than the first. |
Flag this Question
Question 51 pts
Which of the following can be included in a variavble name?
Flag this Question
Question 61 pts
Which of the options are correct for the following code? char a = 'a'; // line 1 char b = b; // line 2 char c = '1'; // line 3 int d = 1; // line 4
| Code at line 2 fails to compile. |
| Code at line 3 fails to compile. |
| Code at line 4 fails to compile. |
| Code at line 1 fails to compile. |
Flag this Question
Question 71 pts
What is the output of a program with the following lines of code?
char s[] = "Fine"; *s = 'N'; printf("%s", s);
Flag this Question
Question 81 pts
Which of the following operator can be used to access value at address stored in a pointer variable?
Flag this Question
Question 91 pts
Which option is correct for calling the following function from another function?
int function(int *a, int *b) { int temp = (*a)+(*b); *a = 3*temp - (2*(*b))%9; *b = (*a)%temp; printf("a = %d, b = %d ", *a, *b); return (*a) - (*b); }
| int a = 2, b = 1; b = function([]a, []b); |
| int a = 2, b = 1; b = function(*a, *b); |
| int a = 2, b = 1; b = function(a, b); |
| int a = 2, b = 1; b = function(&a, &b); |
Flag this Question
Question 101 pts
Which option is correct for calling the following function from another function?
void function(int array[], int length) { int i; int temp[length]; for (i=0; i | int values[] = {3, 0, 4, 5, 1, 2}; function(values, 6); |
| int values[] = {3, 0, 4, 5, 1, 2}; function(values[], 6); |
| int values[] = {3, 0, 4, 5, 1, 2}; function(*values, 6); |
| int values[] = {3, 0, 4, 5, 1, 2}; function(values[0], 6); |
Flag this Question
Question 111 pts
extern int fun(); - The declaration indicates the presence of a global function defined outside the current module or in another file.
Flag this Question
Question 121 pts
In this code segment, which line causes an array index "out of bounds" first?
int nums[10], i; // line 1 for (i=1; i<10; i++) // line 2 nums[i-1] = 2*i+5; // line 3 i = 0; // line 4 while (i < 10) { // line 5 int t = nums[i+1]; // line 6 nums[i] = nums[t]; // line 7 i++; // line 8 }
Flag this Question
Question 131 pts
Which of the following correctly opens the file "num.txt" to read from?
| FILE* ifp = fopen("num.txt", "r"); |
| FILE* ifp = fopen("num.txt"); |
| FILE* ifp = fopen(num.txt, r); |
| FILE* ifp = fopen("num.txt", r); |
Flag this Question
Question 141 pts
What is the output of the following lines of code when fun2 is called from a main() function in a c program?
line 1: void fun1(int *a) line 2: { line 3: a = (int*)malloc(sizeof(int)); line 4: } line 5: int fun2() line 6: { line 7: int *p; line 8: fun1(p); line 9: *p = 6; line 10: printf("%d ",*p); line 11: return(0); line 12: }
Flag this Question
Question 151 pts
What does the following function do?
1. void f(int array[], int length) { 2. int i; 3. int temp = array[0]; 4. for (i=0; i | sorts the values in the array |
| copies the first value into each array element |
| does a left circular shift on the items in the array |
| does a right circular shift on the items in the array |
Flag this Question
Question 161 pts
Given the function x below, what is the value of the expression: x(x(1,2), x(4,3))
1. int x(int a, int b) { 2. if (a < b) 3. return a + b; 4. return a*b; 5. }
Flag this Question
Question 171 pts
Which of the following reads in one integer from the file pointed to by ifp into the variable num?
Flag this Question
Question 181 pts
What restriction on the contents of array guarantees that accessing any elements of array will not cause an array out of bounds error, assume that length is the length of the array?
| All values will be in between 1 and 6, inclusive. |
| All values will be in between 0 and length-1, inclusive. |
| All values will be in between 1 and length, inclusive. |
| All values will be in between 0 and length, inclusive. |
Flag this Question
Question 191 pts
Which of the below three functions are likely to cause problems with pointers?
1. [PI] int * g (void) 2. { 3. int x= 10; 4. return (&x); 5. } 1. [P2] int * g (void) 2. { 3. int * px; 4. *px= 10; 5. return px; 6. } 1. [P3] int *g (void) 2. { 3. int *px; 4. px = (int *) malloc (sizeof(int)); 5. *px= 10; 6. return px; 7. }
Flag this Question
Question 201 pts
Which of the following is/are true?
| calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has random data. |
| malloc() and memset() can be used to get the same effect as calloc(). |
| calloc() takes two arguments, but malloc takes only 1 argument. |
| Both malloc() and calloc() return 'void *' pointer. |
Flag this Question
Question 211 pts
What is the return type of malloc() or calloc() ?
| Pointer of allocated memory type |
Flag this Question
Question 221 pts
What is the problem with following code?
int *p = (int *)malloc(sizeof(int)); p = NULL; free(p);
| Compiler Error: free can't be applied on NULL pointer |
| The program may crash as free() is called for NULL pointer |
Flag this Question
Question 231 pts
Assume that base address of arr is 2000 and size of integer is 32 bit. What is the output of the followinf program?
int arr[5]; arr++; printf("%u", arr);
| Not possible to apply addition. |
Flag this Question
Question 241 pts
What will the following code print?
1. int i; 2. int arr[5] = {1}; 3. for (i = 0; i < 5; i++) 4. printf("%d ", arr[i]);
| 1 followed by four garbage values |
Flag this Question
Question 251 pts
Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements?
| int[][] items = {{1, null, null, null}, {2, 3, 4, 5}, {6, 7, null, null}}; |
| int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}}; |
| int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}, {}); |
| int[][] items = {{1}, {4}, {2}}; |
Flag this Question
Question 261 pts
Which of the following statements are correct about the following function? long fun(int num) { int i; long f=1; for(i=1; i<=num; i++) f = f * i; return f; }
| The function calculates the value of 1 raised to power num. |
| The function calculates the square root of an integer. |
| The function calculates the factorial value of an integer |
Flag this Question
Question 271 pts
C library function __________ is used for comparing arrays of characters to determine whether they are equal and have the same contents.
Flag this Question
Question 281 pts
When fopen() is not able to open a file, it returns
Flag this Question
Question 291 pts
In fopen(), the open mode "wx" is sometimes preferred "w" because.
1) Use of wx is more efficient. 2) If w is used, old contents of file are erased and a new empty file is created. When wx is used, fopen() returns NULL if file already exists.
Flag this Question
Question 301 pts
Which of the following is not a storage class specifier in C?
Flag this Question
Question 311 pts
Information is passed to a function in ________.
| the prameter to the method |
Flag this Question
Question 321 pts
The parameters in the function declaration and the arguments in the function call must agree in:
Flag this Question
Question 331 pts
What is the output of the following problem ?
1. int main() 2. { 3. func(1); 4. return 0; 5. }
6. func(int i){ 7. static char *str[] = {"One","Two", "Three", "Four"}; 8. printf("%s ",str[i++]); 9. return; 10. }
Flag this Question
Question 341 pts
What is the output of the following C Program?
int main() { static char names[5][20]={"Orlando","Atlanta","Austin","New York","Los Angeles"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); return 0; }
| Orlando Atlanta Austin New York Los Angeles |
Flag this Question
Question 351 pts
The expression ((fpt = fopen ("Samples", "w")) == NULL) would be true if
| the file sample does not exist while fopen is being executed |
| the file "sample" could not be created for writing |
| fpt is not declared as a FILE pointer |
| the file "sample" is read only |
Flag this Question
Question 361 pts
x = fopen (b, c) what is b?
| A. pointer to a character array which contains the filename |
| B. filename within double quotes |
Flag this Question
Question 371 pts
float x, y, z; scanf ("%f %f", &x, &y);
If input stream contains "4.2 3 2.3 ..." What will x and y contain after scanf?
Flag this Question
Question 381 pts
What is the output of the following 'C' function when called?
1. void function() { 2. int x = 10,y = 10, z = 5, i; 3. i = x; 4. printf("%d",i==x); 5. }
Flag this Question
Question 391 pts
In a C program, if the initialization statement is:
int x,y=2,z,a;
What would be the value of x when the following line of code is executed?
x = (y*=2) + (z=a=y);
Flag this Question
Question 401 pts
Given the struct xx with the following members:
int x=3; char name[]="hello";
What would be the output of the following program?
1. void main() 2. { 3. struct xx *s=malloc(sizeof(struct xx)); 4. printf("%d",s->x); 5. printf("%s",s->name); 6. }