+ 2
Increment operator...
for(k = 1; k < n; ++k) {...} in this line of code, what will be the value of k before entering in a for loop?
9 Antworten
+ 3
Assuming you declared your variables prior to the loop, the loop would start off with 'k' being equal to 1.
As for if you had 'k' set to another value prior to the loop, I can't answer that without knowing the rest of the code. In this isolated context, 'k' starts as being equal to 1 and increments by one each loop through.
+ 2
k is local to for loop only, no previous initialisation done
+ 2
int fun(int n) {
int x=1, k;
if (n==1) return(1);
for(k=1; k<n; ++k){
x = x+fun(k)*fun(n-k);
return(x);
}
}
Now tell me what will be the output of fun(5)?
if possible, plz give detailed explanation.
+ 1
Nilesh Ingale in this code snippet k isn't declared in the for loop as Jakob Marley already mentioned. The scope of k isn't limited to the for loop on this case.
constructing the loop without for would look like this:
int k = ???
int n = ???
//code snippet begins
k=1;
while (k<n){
...
++k;
}
//code snippet ends
+ 1
wait i'll post whole code here
+ 1
This fun() does not go on forever as there will be a condition of fun(1) which will return the value 1 and it will terminate the loop.
0
Before the loop actually starts looping k is set to 1 if that was your question Nilesh Ingale
0
this is a recursive function which i think probably goes on forever as long as fun() is being called inside.prove me wrong pls
0
It should be "2" because ++k means k increment before execution of the loop