UGC NET CS 2017 Nov- paper-3
October 5, 2023NTA-UGC-NET 2021 Dec & 2022 June Paper-2
October 5, 2023Nielit Scientific Assistance IT 15-10-2017
Question 1 |
What will be the output of following?
main()
{
static int a=3;
printf(“%d”,a–);
if(a)
main();
}
main()
{
static int a=3;
printf(“%d”,a–);
if(a)
main();
}
3 | |
3 2 1 | |
3 3 3 | |
Program will fall in continuous loop and print 3 |
Question 1 Explanation:
The variable is static variable, the value is retained during multiple function calls. Initial value is 3
“A–” is post decrement so it will print “3”
if(2) condition is true and main() function will call again , Here the “a” value is 2.
“A–” is post decrement so it will print “2”
if(1) condition is true and main() function will call again Here the “a” value is 1.
“A–” is post decrement so it will print “1”
if(0) condition is false it won’t call main() function
“A–” is post decrement so it will print “3”
if(2) condition is true and main() function will call again , Here the “a” value is 2.
“A–” is post decrement so it will print “2”
if(1) condition is true and main() function will call again Here the “a” value is 1.
“A–” is post decrement so it will print “1”
if(0) condition is false it won’t call main() function
Correct Answer: B
Question 1 Explanation:
The variable is static variable, the value is retained during multiple function calls. Initial value is 3
“A–” is post decrement so it will print “3”
if(2) condition is true and main() function will call again , Here the “a” value is 2.
“A–” is post decrement so it will print “2”
if(1) condition is true and main() function will call again Here the “a” value is 1.
“A–” is post decrement so it will print “1”
if(0) condition is false it won’t call main() function
“A–” is post decrement so it will print “3”
if(2) condition is true and main() function will call again , Here the “a” value is 2.
“A–” is post decrement so it will print “2”
if(1) condition is true and main() function will call again Here the “a” value is 1.
“A–” is post decrement so it will print “1”
if(0) condition is false it won’t call main() function
Subscribe
Login
0 Comments