proc() {
static i=10;
printf("%d",i);
}
If this proc() is called second time, what is the output?
Answers were Sorted based on User's Feedback
Answer / sujith
I dont know how can it be 11 next time.
I agree that static variables are assigned only once, and
allocation is happening to the data segment, but it doesnt
mean that is going to change the value on its own, until u
do that manually.
U call this program for n times, the answer is going to be 10.
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / suchita
the answer is 10 bcoz no increment statement in that loop. if
increment statement is there then definitely the value of
static variable is increased. otherwise it is fixed.
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / vignesh1988i
if it is called for second time also ,it will be 10 only but
in a different thought....
static keyword is only one time initilization....if the
compailer when again reads the same line it blindly ignores
it and print the latest value of yhat static variable
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / jeevan
There is not increment statement. In this case, always it
returs 10 only. even if 'i' is not static type, then also
it returns 10 only....... for confusing in interview, they
might have used 'static' key word here.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / saurabh
does static function increment the counter variable by
one?? if not then how can u say that i value will be
incremented by 1.
finally the i value will be 10 only. it will not
increment.
Is This Answer Correct ? | 1 Yes | 1 No |
What is the difference between formatted&unformatted i/o functions?
what will be the result of the following program ? char *gxxx() { static char xxx[1024]; return xxx; } main() { char *g="string"; strcpy(gxxx(),g); g = gxxx(); strcpy(g,"oldstring"); printf("The string is : %s",gxxx()); } a) The string is : string b) The string is :Oldstring c) Run time error/Core dump d) Syntax error during compilation e) None of these
Explain goto?
what is the output of the program?? #include<stdio.h> main ( ) { int a=010,sum=0,tracker: for(tracker=0;tracker<=a;tracker++) sum+=tracker; printf(ā %d\nā,sum); } what is the difference between a=10 and a=010??
6)What would be the output? main() { int u=1,v=3; pf("%d%d",u,v); funct1(&u,&v); pf("%d%d\n",u,v); } void funct1(int *pu, int *pv) { *pu=0; *pv=0; return; } a)1 3 1 3 b)1 3 1 1 c)1 3 0 0 d)1 1 1 1 e) 3 1 3 1
Find errors (1) m = ++a*5; (2) a = b ++ -c*2; (3)y = sqrt (1000);
stripos ā Find position of first occurrence of a case- insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls.
what is pointer?
13 Answers HCL, TCS,
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What is the output from this program? #include <stdio.h> void do_something(int *thisp, int that) { int the_other; the_other = 5; that = 2 + the_other; *thisp = the_other * that; } int main(void) { int first, second; first = 1; second = 2; do_something(&second, first); printf("%4d%4d\n", first, second); return 0; }
How would you sort a linked list?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?