Scope of a Variable MCQ Quiz in বাংলা - Objective Question with Answer for Scope of a Variable - বিনামূল্যে ডাউনলোড করুন [PDF]
Last updated on Mar 9, 2025
Latest Scope of a Variable MCQ Objective Questions
Top Scope of a Variable MCQ Objective Questions
Scope of a Variable Question 1:
Consider the following C program
#include
int main()
{
int a = 21;
int b, b1;
b = a++;
b1 = ++a;
++a;
a--;
b-=a--;
printf("%d",b);
return 0;
}
The output of the above code is _____.Answer (Detailed Solution Below) -2
Scope of a Variable Question 1 Detailed Solution
int main()
{
int a = 21;
int b, b1;
b = a++; / b = 21 , a = 22
b1 = ++a; / b1 = 23, a = 23
++a; / a = 24
a--; / a = 23
b -= a--; /b = -2, a = 22
printf("%d",b); / value of b is printed, that is, -2
return 0;
}
Output = -2Scope of a Variable Question 2:
What is the output of the following statement?
int a = 24;
a = 24<<2;
printf("%d",a);Answer (Detailed Solution Below)
Scope of a Variable Question 2 Detailed Solution
<< → bitwise left shift operator (multiplication)
Binary representation of 24: 0001 1000
Binary representation of 24<<2: 0110 0000 (2 bit shifted to left)
0110 0000 → In decimal Number system is 96
Tricks: 24 × 22 = 96
Note:
- Assume integer is of 8 bits, even if integer size is more than that it won’t affect the answer
- Overflow will give you in appropriate result if range exceeds the range of integer of a system
Scope of a Variable Question 3:
What is the output of the following statement in C?
int c=31;
printf("%x",c);Answer (Detailed Solution Below)
Scope of a Variable Question 3 Detailed Solution
- Since variable c doesn’t contain any suffix, 31 is a decimal number
- In printf function, %x is used as a conversion specifier for hexadecimal number, 31 is a decimal number which gets converted in to hexadecimal number; 3110(decimal)=1f16(hexadecimal)
Conversion of decimal number (15) to octal number (17)
31÷ 16=1remainder: 15(f)
1÷ 16=remainder: 1
Take the remainder in bottom-up fashion: 1f
- In hexadecimal number system, a→ 10, b→ 11, c→ 12, d→ 13, e→ 14, f→ 15, and (0-9) is same as decimal
Notes:
A→ 10 means A is hexadecimal number that corresponds to decimal value 10.
Base 10 is used for decimal number.
Base 16 is used for hexadecimal number.Scope of a Variable Question 4:
What is the output of the following program?
#include
int tmp = 20;
main( )
{
printf("%d ",tmp);
func( );
printf("%d ",tmp);
}
func( )
{
static int tmp = 10;
printf("%d ",tmp);
}
Answer (Detailed Solution Below)
Scope of a Variable Question 4 Detailed Solution
#include
int tmp = 20;
main( )
{
printf("%d ",tmp); / 20 will be printed here as "tmp" is a global variable.
func( );
printf("%d ",tmp); / 20 will be printed because global "tmp" variable is still unchanged.
}
func( )
{
static int tmp = 10; / static "tmp" has local scope.
printf("%d ",tmp); / 10 will be printed here.
}
Scope of a Variable Question 5:
#include
int foo(int x);
int x = 10;
int main( ) {
x = 1;
printf("%d", x);
foo(x);
printf("%d", x);
}
int foo(int x) {
printf("%d", x);
x += 4;
printf("%d", x);
return x;
}
What does above C program print?
Answer (Detailed Solution Below) 1151
Scope of a Variable Question 5 Detailed Solution
Scope of a Variable Question 6:
_______ are words that a programming language has set aside for its own use.
Answer (Detailed Solution Below)
Scope of a Variable Question 6 Detailed Solution
Concept:
Reserved words are the words that a programming language set aside for its own use. These are appropriated for special use that will not be utilized in the creation of variable names.
Explanation:
Some points about reserved words :
- Reserved words are used in the operating system to identify a file or another service.
- When there is an attempt to access reserved words in the operating system then it results in an error message.
- Each programming language has its own set of keywords.
- Some programming languages are without any reserved words such as PL/I.
- Sometimes a language might reserve some words for use by language but not give them special meaning, to use them is still an error.
Scope of a Variable Question 7:
Consider the following code segment:
int x=22, y=15;
x = (x > y) ? (x + y) : (x-y);
What will be the value of x after the code is executed?Answer (Detailed Solution Below)
Scope of a Variable Question 7 Detailed Solution
This is a conditional statement:
In which if condition before “?” is true then output will be the statement before “:” operator otherwise output will be the statement after “:”.
Here given code is:
int x=22, y=15;
x=(x>y)?(x + y):(x-y); / 22 > 15 (condition is true), so output will be 22 + 15 i.e. 37
So, output will be x = 37.
Note:
?: → ternary operator
Scope of a Variable Question 8:
What is the output of this program ? ]
void main()
{
int a=b=c=10;
a=b=c=50;
printf(“\n %d %d %d”,a,b,c);
}Answer (Detailed Solution Below)
Scope of a Variable Question 8 Detailed Solution
On Compilation the error message displayed is:
error: ‘b’ undeclared (first use in this function)
Which means the variable b is undefined and it is assigned value which is incorrect.Scope of a Variable Question 9:
Which of the following escape sequence positions the cursor at the beginning of the next line?
Answer (Detailed Solution Below)
Scope of a Variable Question 9 Detailed Solution
An escape sequence like \n provides a general and extensible mechanism for representing hard-to-type or invisible characters.
The sequence \n in the string is C notation for the newline character, which when printed advances the output to the left margin on the next line.
Escape Sequence |
Description |
\n |
Newline |
\t |
Tab |
\b |
Backspace |
\” |
Double quote |
\\ |
backslash |
Scope of a Variable Question 10:
What is the purpose of the scanf command?