...
Functions
October 18, 2024
Functions
October 18, 2024

Functions

Question 12
The integer value printed by the ANSI-C program given below is_____ .
#include
int funcp(){
static int x = 1;
x++;
return x;
}
int main(){
int x,y;
x = funcp();
y = funcp()+x;
printf(“%d\n”, (x+y));
return 0;
}

A
7
Question 12 Explanation: 
int funcp(){
static int x = 1; // here “x” is a static variable and the updated value will be carried for all remaining function calls.
x++;
return x; // incremented value will be returned to calling function
}
int main(){
int x,y;
x = funcp(); // funcp() will return the value “2” and value “2” will stored in the variable “x”
y = funcp()+x; //funcp() will return the value “3” and it will be added to “2” and value “5” be stored in the variable “y”
printf(“%d\n”, (x+y)); // 2+5 =7 value will be displayed
return 0;
}
Correct Answer: A
Question 12 Explanation: 
int funcp(){
static int x = 1; // here “x” is a static variable and the updated value will be carried for all remaining function calls.
x++;
return x; // incremented value will be returned to calling function
}
int main(){
int x,y;
x = funcp(); // funcp() will return the value “2” and value “2” will stored in the variable “x”
y = funcp()+x; //funcp() will return the value “3” and it will be added to “2” and value “5” be stored in the variable “y”
printf(“%d\n”, (x+y)); // 2+5 =7 value will be displayed
return 0;
}
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!