01)Except the first dimension, every other dimension must be specified.
int arr[] = {5, 6, 7, 8} //valid
int arr[][5] = {}; //valid
int arr[][] = {}; //invalid
int arr[][10][5] = {}; //valid
int arr[][][5] = {}; //invalid
02)What is the use of typedef?
Ans: The typedef help in easier modification when the programs are ported to another machine.
A descriptive new name given to the existing data type may be easier to understand the code.
03)What are register variables? What are the advantages of using register variables?
Ans: If a variable is declared with a register storage class,it is known as register variable.The
register variable is stored in the cpu register instead of main memory.Frequently used variables
are declared as register variable as it‘s access time is faster
04)In header files whether functions are declared or defined?
Ans: Functions are declared within header file. That is function prototypes exist in a header
file,not function bodies. They are defined in library (lib).
05)What are the uses of a pointer?
Ans: Pointer is used in the following cases
i) It is used to access array elements
ii) It is used for dynamic memory allocation.
iii) It is used in Call by reference
iv) It is used in data structures like trees, graph, linked list etc.
06)What does static variable mean?
Ans: Static variables are the variables which retain their values between the function calls. They
are initialized only once their scope is within the function in which they are defined.
07)What is a memory leak?
Its an scenario where the program has lost a reference to an area in the memory. Its a
programming term describing the loss of memory. This happens when the program
allocates some memory but fails to return it to the system
08)What is the difference between an array of pointers and a pointer to an
array?
This is an array of pointers
int *p[10];
This is a pointer to a 10 element array
int (*p)[10];
09)What is the difference between Merge Sort and Quick sort?
Both Merge-sort and Quick-sort have same time complexity i.e. O(nlogn). In merge
sort the file a[1:n] was divided at its midpoint into sub-arrays which are
independently sorted and later merged. Whereas, in quick sort the division into two
sub-arrays is made so that the sorted sub-arrays do not need to be merged latter.
10)What is the output of this C code?
#include <stdio.h>
struct student
{
};
void main()
{
struct student s[2];
printf("%d", sizeof(s));
}
a) 2
b) 4
c) 8
d) 0
Answer:d
11)What does the following C statement mean?
scanf("%4s", str);
(A)Read exactly 4 characters from console.
(B) Read maximum 4 characters from console.
(C) Read a string str in multiples of 4
(D) Nothing
Answer: (B)
12)int main()
{
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf("%d ", arr[i]);
return 0;
}
(A) 1 followed by four garbage values
(B) 1 0 0 0 0
(C) 1 1 1 1 1
(D) 0 0 0 0 0
Answer: (B)
13)Assume that the size of an integer is 4 bytes. Predict the output?
#include <stdio.h>
int fun()
{
puts(" Hello ");
return 10;
}
int main()
{
printf("%d", sizeof(fun()));
return 0;
}
(A) 4
(B) Hello 4
(C) 4 Hello
(D) Compiler Error
Answer: (A)
Explanation: sizeof() is an operator, not a function. It looks like a function though.
The operands of operators need not to be evaluated. That is why fun() is not called.
14)#include <stdio.h>
int main()
{
int arr[] = {1, 2, 3, 4, 5};
int *p = arr;
++*p;
p += 2;
printf("%d", *p);
return 0;
}
(A) 2
(B) 3
(C) 4
(D) Compiler Error
Answer: (B)
Explanation: The expression ++*p is evaluated as “++(*p)” . So it increments the value of first element of array (doesn’t change the pointer p).
When p += 2 is done, p is changed to point to third element of array.
15)Assume that a character takes 1 byte. Output of following program?
#include<stdio.h>
int main()
{
char str[20] = "CSETEchPause";
printf ("%d", sizeof(str));
return 0;
}
(A)9
(B) 10
(C) 20
(D) Garbage Value
Answer: (C)
Explanation: Note that the sizeof() operator would return size of array. To get size of string stored in array, we need to use strlen(). The following program prints 9.
#include <stdio.h>
#include <string.h>
int main()
{
char str[20] = "CSTechPause";
printf ("%d", strlen(str));
return 0;
}
0 comments:
Post a Comment