Computer-Networks
December 1, 2023Question 8878 – ISRO CS 2020
December 1, 2023Programming-for-Output-Problems
Question 19
|
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 19 Explanation:
Step-1: initial a=3 but we are given storage class is static.
Step-2: In printf( ) we are given post decrement. So, it will print 3 then decrements.
Step-3: if(2) then we are calling main() function, a=2 because of static otherwise it will be 3 only.
Step-4: It will print 2 and next iteration will print 1.
Step-2: In printf( ) we are given post decrement. So, it will print 3 then decrements.
Step-3: if(2) then we are calling main() function, a=2 because of static otherwise it will be 3 only.
Step-4: It will print 2 and next iteration will print 1.
Correct Answer: B
Question 19 Explanation:
Step-1: initial a=3 but we are given storage class is static.
Step-2: In printf( ) we are given post decrement. So, it will print 3 then decrements.
Step-3: if(2) then we are calling main() function, a=2 because of static otherwise it will be 3 only.
Step-4: It will print 2 and next iteration will print 1.
Step-2: In printf( ) we are given post decrement. So, it will print 3 then decrements.
Step-3: if(2) then we are calling main() function, a=2 because of static otherwise it will be 3 only.
Step-4: It will print 2 and next iteration will print 1.
Subscribe
Login
0 Comments