#include<stdio.h>
int main()
{
int k, num=30;
k = (num>5 ? (num <=10 ? 100 : 200): 500);
printf("%d\n", num);
return 0;
}
A.
200
B.
30
C.
100
D.
500
Answer: Option B
Explanation:
Step 1: int k, num=30; here variable k and num are declared as an integer type and variable num is initialized to '30'. Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does not affect the output of the program. Because we are going to print the variable num in the next statement. So, we skip this statement. Step 3: printf("%d\n", num); It prints the value of variable num '30' Step 3: Hence the output of the program is '30'
Floating point formats not linked (Run time error)
C.
Cannot use scanf() for structures
D.
Strings cannot be nested inside structures
Answer: Option B
Explanation:
Compile and Run the above program in Turbo C:
C:\>myprogram.exe
Sundar
2555.50
scanf : floating point formats not linked
Abnormal program termination
The program terminates abnormally at the time of entering the float value for e[i].sal.
Solution:
Just add the following function in your program. It will force the compiler to include required libraries for handling floating point linkages.
static void force_fpf() /* A dummy function */
{
float x, *y; /* Just declares two variables */
y = &x; /* Forces linkage of FP formats */
x = *y; /* Suppress warning message about x */
}
The keyword used to transfer control from a function back to the calling function is
A.
switch
B.
goto
C.
go back
D.
return
Answer: Option D
Explanation:
The keyword return is used to transfer control from a function back to the calling function.
Example:
#include<stdio.h>
int add(int, int); /* Function prototype */
int main()
{
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
return 0;
}
int add(int a, int b)
{
/* returns the value and control back to main() function */
return (a+b);
}
Which of the following statements are correct about an array?
1:
The array int num[26]; can store 26 elements.
2:
The expression num[1] designates the very first element in the array.
3:
It is necessary to initialize the array at the time of declaration.
4:
The declaration num[SIZE] is allowed if SIZE is a macro.
A.
1
B.
1,4
C.
2,3
D.
2,4
Answer: Option B
Explanation:
1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.
3. It is necessary to initialize the array at the time of declaration. This statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.
Hence the statements '1' and '4' are correct statements.
The library function used to find the last occurrence of a character in a string is
A.
strnstr()
B.
laststr()
C.
strrchr()
D.
strstr()
Answer: Option C
Explanation:
Declaration: char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char text[] = "I learn through IndiaBIX.com";
char *ptr, c = 'i';
ptr = strrchr(text, c);
if (ptr)
printf("The position of '%c' is: %d\n", c, ptr-text);
else
printf("The character was not found\n");
return 0;
}
The following is the example program to explain "using bit fields inside an union".
#include<stdio.h>
union Point
{
unsigned int x:4;
unsigned int y:4;
int res;
};
int main()
{
union Point pt;
pt.x = 2;
pt.y = 3;
pt.res = pt.y;
printf("\n The value of res = %d" , pt.res);
return 0;
}
// Output: The value of res = 3