Scope of a Variable MCQ Quiz in বাংলা - Objective Question with Answer for Scope of a Variable - বিনামূল্যে ডাউনলোড করুন [PDF]

Last updated on Mar 9, 2025

পাওয়া Scope of a Variable उत्तरे आणि तपशीलवार उपायांसह एकाधिक निवड प्रश्न (MCQ क्विझ). এই বিনামূল্যে ডাউনলোড করুন Scope of a Variable MCQ কুইজ পিডিএফ এবং আপনার আসন্ন পরীক্ষার জন্য প্রস্তুত করুন যেমন ব্যাঙ্কিং, এসএসসি, রেলওয়ে, ইউপিএসসি, রাজ্য পিএসসি।

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 = -2

Scope of a Variable Question 2:

What is the output of the following statement?

int a = 24;

a = 24<<2;

printf("%d",a);

  1. 26
  2. 48
  3. 96
  4. 6

Answer (Detailed Solution Below)

Option 3 : 96

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);

  1. 31
  2. 1f
  3. 37
  4. 1A

Answer (Detailed Solution Below)

Option 2 : 1f

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);

}

  1. 20 10 10
  2. 20 10 20
  3. 20 20 20
  4. 10 10 10

Answer (Detailed Solution Below)

Option 2 : 20 10 20

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

Concept of the scope of the variable applies in this problem. Variable x has local and global scope.

Scope of a Variable Question 6:

_______ are words that a programming language has set aside for its own use.

  1. Reserved Keys
  2. Control Structures
  3. Reserved words
  4. Control Words

Answer (Detailed Solution Below)

Option 3 : Reserved words

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?

  1. 22
  2. 37
  3. 7
  4. 37 and 7

Answer (Detailed Solution Below)

Option 2 : 37

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);

 }

  1. 50 50 50
  2. Compile Time Error 
  3. 10 10 10
  4. Three Garbage Value

Answer (Detailed Solution Below)

Option 2 : Compile Time Error 

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?

  1. \t
  2. \b
  3. \n
  4. \”

Answer (Detailed Solution Below)

Option 3 : \n

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?

  1. to process single character
  2. to process character and strings
  3. to process any possible number
  4. to process any possible variable type

Answer (Detailed Solution Below)

Option 4 : to process any possible variable type

Scope of a Variable Question 10 Detailed Solution

The programming language, scanf is the short form of scan formatted. It is a keyword used as a control parameter meant for reading a string. The string is picked up from the standard input device itself.
Get Free Access Now
Hot Links: teen patti app teen patti gold teen patti jodi