

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
What will be the output of the program (in Turbo C)? |
Answer» Step 1: const int arr[5] = {1, 2, 3, 4, 5}; The constant variable arr is declared as an integer array and initialized to arr[0] = 1, arr[1] = 2, arr[2] = 3, arr[3] = 4, arr[4] = 5 Step 2: printf("Before modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 4). Step 3: fun(&arr[3]); The memory location of the arr[3] is passed to fun() and arr[3] value is modified to 10. A const variable can be indirectly modified by a pointer. Step 4: printf("After modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 10). Hence the output of the program is Before modification arr[3] = 4 After modification arr[3] = 10 | |
2. |
Point out the error in the program. |
Answer» Step 1: char mybuf[] = "India"; The variable mybuff is declared as an array of characters and initialized with string "India". Step 2: char yourbuf[] = "BIX"; The variable yourbuf is declared as an array of characters and initialized with string "BIX". Step 3: char *const ptr = mybuf; Here, ptr is a constant pointer, which points at a char. The value at which ptr it points is not a constant; it will not be an error to modify the pointed character; There will be an error only to modify the pointer itself. Step 4: *ptr = 'a'; The value of ptr is assigned to 'a'. Step 5: ptr = yourbuf; Here, we are changing the pointer itself, this will result in the error "cannot modify a const object". | |
3. |
Point out the error in the program (in Turbo-C). |
Answer» Step 1: A macro named MAX is defined with value 128 Step 2: const int max=128; The constant variable max is declared as an integer data type and it is initialized with value 128. Step 3: char array[max]; This statement reports an error "constant expression required". Because, we cannot use variable to define the size of array. To avoid this error, we have to declare the size of an array as static. Eg. char array[10]; or use macro char array[MAX]; Note: The above program will print A A as output in Unix platform. | |