Variables
- What would be the output of following program ?
int x = 15;
main()
{
int x = 60;
print("\n%d", x);
}
-
View Hint View Answer Discuss in Forum
Whenever there is a conflict between local and global variable, the local variable wins.
Correct Option: C
Whenever there is a conflict between local and global variable, the local variable wins. So In this question local variable gets priority over global.
- Which of the following is the correct output for the program given below?
#include <studio.h>
int main()
{
extern int x;
x = 30;
printf("%d\n", sizeof(x));
return 0;
}
-
View Hint View Answer Discuss in Forum
extern int x is a declaration and not a definition.
Correct Option: D
extern int x is a declaration and not a definition, hence the error.
- Which of the following is the correct output for the program given below?
#include <studio.h>
int main()
{
extern int k;
printf("%d\n", k );
return 0;
}
int k = 30;
-
View Hint View Answer Discuss in Forum
No Error.
Correct Option: A
No error, When we use extern keyword with uninitialized variable compiler think variable has initialized somewhere else in the program while when we don't use extern keyword then compiler initialized it with default value.
So output is 30.
- Which of the following is the correct output for the program given below ?
#include <studio.h>
int main()
{
extern int fun (float);
int k;
k = fun (5.74);
printf ("%d\n", k);
return 0;
}
int fun (kk)
float kk;
{
return ((int) kk);
}
-
View Hint View Answer Discuss in Forum
The error occurs because we have mixed the ANSI prototype with Kernighan & Ritchie style of function definition.
Correct Option: D
The error occurs because we have mixed the ANSI prototype with Kernighan & Ritchie style of function definition.
When we use ANSI prototype for a function and pass a float to the function it is promoted to a double.
When the function accepts this double into a float a type mismatch occurs hence the error. The remedy for this error could be to define the function as:
int fun ( float kk)
{
// code here
}
- Which of the following set of statement is correct ?
-
View Hint View Answer Discuss in Forum
In the second statement the a will be replaced by its data type i.e. long.
Correct Option: C
In the second statement the a will be replaced by its data type.
So
Option A will be extern int long c;
Option B will be extern long int c;
Option C will be extern logn c;
So here only option C is correct.