skip to main
|
skip to sidebar
C Programming
Pages
Home
Programs
Pointer
Projects
Solution
Variable naming rule questions in c language
Following question are based on
variable naming rules
in c. If you have any doubt in the variable naming rules you can ask here.
Rules for identifiers in c language
1.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
goto
=5;
printf(
"%d"
,
goto
);
return
0;
}
(A)
5
(B)
**
(C)
**
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Invalid variable name.
goto
is keyword in c. variable name cannot be any keyword of c language.
2.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
long
int
1a=5l;
printf(
"%ld"
,1a);
return
0;
}
(A)
5
(B)
51
(C)
6
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Invalid variable name. Variable name must star from either alphabet or
underscore.
3.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
_=5;
int
__=10;
int
___;
___=_+__;
printf(
"%i"
,___);
return
0;
}
(A)
5
(B)
10
(C)
15
(D)
Compilation error
(E)
None of these
Correct Option is : (C)
Explanation:
Variable name can have only underscore.
4.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
max-val=100;
int
min-val=10;
int
avg-val;
avg-val = max-val + min-val / 2;
printf(
"%d"
,avg-val);
return
0;
}
(A)
55
(B)
105
(C)
60
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
We cannot use special character – in the variable name.
5.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
class=150;
int
public=25;
int
private=30;
class = class >> private - public;
printf(
"%d"
,class);
return
0;
}
(A)
1
(B)
2
(C)
4
(D)
Compilation error
(E)
None of these
Correct Option is : (C)
Explanation:
Variable name can be keyword of c++.
6.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
abcdefghijklmnopqrstuvwxyz123456789=10;
int
abcdefghijklmnopqrstuvwxyz123456=40;
printf(
"%d"
,abcdefghijklmnopqrstuvwxyz123456);
return
0;
}
(A)
10
(B)
40
(C)
50
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Only first 32 characters are significant in variable name. So compiler will show error: Multiple declaration of identifier abcdefghijklmnopqrstuvwxyz123456.
7.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
register
xyz_123=91;
auto
pqr_123=991;
const
_1a1_=pqr_123+~xyz_123;
printf(
"%d"
,_1a1_);
return
0;
}
(A)
900
(B)
999
(C)
899
(D)
Compilation error
(E)
None of these
Correct Option is : (C)
Explanation:
Variable name can have digits.
8.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
__SMALL__ = 11;
int
y;
y= __SMALL__ < 5;
printf(
"%d"
,y);
return
0;
}
(A)
11
(B)
5
(C)
0
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Variable name cannot be global identifier.
9.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
__BIG__ = 32;
int
y;
y= __BIG__ && 8;
printf(
"%d"
,y);
return
0;
}
(A)
32
(B)
8
(C)
1
(D)
Compilation error
(E)
None of these
Correct Option is : (C)
Explanation:
Variable name can be in the format: __NAME__. But it is bad practice since this format is used for global identifiers.
10.
What will be output of the following c program?
#include
<stdio.h>
static
num=5;
int
num;
extern
int
num;
int
main(){
printf(
"%d"
,num);
return
0;
}
(A)
5
(B)
10
(C)
0
(D)
Compilation error
(E)
None of these
Correct Option is : (A)
Explanation:
Two or more global variables can have same name but we can initialize only one of them.
11.
What will be output of the following c program?
#include
<stdio.h>
static
num=5;
extern
int
num;
int
main(){
printf(
"%d"
,num);
return
0;
}
int
num =25;
(A)
0
(B)
5
(C)
25
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Two or more global variables can have same name but we can initialize only one of them.
12.
What will be output of the following c program?
#include
<stdio.h>
static
num;
int
main(){
printf(
"%d"
,num);
return
0;
}
int
num =25;
(A)
0
(B)
1
(C)
25
(D)
Compilation error
(E)
None of these
Correct Option is : (C)
Explanation:
Two or more global variables can have same name but we can initialize only one of them.
13.
What will be output of the following c program?
#include
<stdio.h>
int
xyz=10;
int
main(){
int
xyz=20;
printf(
"%d"
,xyz);
return
0;
}
(A)
10
(B)
20
(C)
30
(D)
Compilation error
(E)
None of these
Correct Option is : (B)
Explanation:
Two variables can have same name in different scope.
14.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
xyz=20;
int
xyz;
printf(
"%d"
,xyz);
return
0;
}
(A)
20
(B)
0
(C)
Garbage
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Two local variables cannot have same name in same scope.
15.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
xyz=20;{
int
xyz=40;
}
printf(
"%d"
,xyz);
return
0;
}
(A)
20
(B)
40
(C)
0
(D)
Compilation error
(E)
None of these
Correct Option is : (A)
Explanation:
Two variables can have same name in different scope.
16.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
main = 80;
printf(
"%d"
,main);
return
0;
}
(A)
80
(B)
0
(C)
Garbage value
(D)
Compilation error
(E)
None of these
Correct Option is : (A)
Explanation:
Variable name can be main.
17.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
struct
a{
int
a
;
};
struct
a b={10};
printf(
"%d"
,b.
a
);
return
0;
}
(A)
0
(B)
10
(C)
Garbage value
(D)
Compilation error
(E)
None of these
Correct Option is : (B)
Explanation:
Two variables can have same name in different scope.
18.
What will be output of the following c program?
#include
<stdio.h>
int
main
(){
int
ABC=10;
printf(
"%d"
,abc);
return
0;
}
(A)
10
(B)
0
(C)
5
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Variable name is case sensitive.
19.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
printf=12;
printf(
"%d"
,printf);
return
0;
}
(A)
12
(B)
0
(C)
5
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Variable name cannot be pre defined function of included header file.
20.
What will be output of the following c program?
#include
<stdio.h>
int
main(){
int
EOF=12;
printf(
"%d"
,EOF);
return
0;
}
(A)
12
(B)
0
(C)
5
(D)
Compilation error
(E)
None of these
Correct Option is : (D)
Explanation:
Variable name cannot be pre defined function of included header file.
0 comments:
Post a Comment
Newer Post
Older Post
Home
Category
Concepts
(16)
Graphics Program
(3)
Hardware interaction through C
(9)
Pointers Tutorial
(29)
Problem
(1)
Program
(196)
Projects
(3)
Puzzles Program
(7)
Question and Answer
(15)
Solution
(4)
System Program
(9)
Virus Program
(2)
Powered by
Blogger
.
Popular Posts
Find G.C.D of two numbers using c language | CTechnotips
Definition of HCF ( Highest common facto r ): HFC is called Greatest Common Divisor (GCD) . HCF of Two Numbers is a Largest Posit...
sorting of array using pointer in c language | | CTechnotips
Write a c program for sorting of array using pointer. int main(){ int i,j,temp1,temp2; int arr[8]={5,3,0,2,12,1...
check given number is prime number or not using c program | CTechnotips
Definition of prime number: A natural number greater than one has not any other divisors except 1 and itself. In other word we can say...
A Car Racing Game ( Mini Project ) in c language | CTechnotips
/* Language: C\C++ (To convert to C, just change cout to printf and cin to scanf and change the library files) Category: Games\Graphics...
check the given number is palindrome number or not using c program | CTechnotips
Definition of Palindrome number or What is palindrome number? A number is called palindrome number if it is remain same when its ...
10 Challenging star pattern programs in C
Computer languages are not as easy as human languages, they need you to become a computer yourself, think like a computer and write an al...
write a c program to find out sum of digit of given number | CTechnotips
Code 1: 1. C program to add digits of a number 2. C program for sum of digits of a number 3. C program to calculate sum of d...
Split number into digits in c programming | CTechnotips
Extract digits from integer in c language #include <stdio.h> int main(){ int num,temp,factor=1; printf( "...
Find out the perfect number using c program | CTechnotips
Definition of perfect number or What is perfect number? Perfect number is a positive number which sum of all positive divisors ...
c program for odd or even number | CTechnotips
Algorithm: Number is called even number if it is divisible by two otherwise odd. Example of even numbers: 0,2,4,8,9,10 etc. Exam...
0 comments:
Post a Comment