C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 8)
8.
What will be the output of the program ?
#include<stdio.h>
int *check(static int, static int);
int main()
{
int *c;
c = check(10, 20);
printf("%d\n", c);
return 0;
}
int *check(static int i, static int j)
{
int *p, *q;
p = &i;
q = &j;
if(i >= 45)
return (p);
else
return (q);
}
Discussion:
50 comments Page 2 of 5.
Rocky said:
1 decade ago
Line 13: error: storage class specified for parameter 'type name'
Line 13: error: storage class specified for parameter 'type name'
Line 22: error: storage class specified for parameter 'i'
Line 22: error: storage class specified for parameter 'j'
Line 13: error: storage class specified for parameter 'type name'
Line 22: error: storage class specified for parameter 'i'
Line 22: error: storage class specified for parameter 'j'
M@c said:
1 decade ago
#include<stdio.h>
int static a=1;
int main()
{
static int a=10;
a++;
call();
return 0;
}
call()
{
printf("Weclome to IndiaBIX.com..! %d",a);
}
o/p :
Weclome to IndiaBIX.com..! 1
Please Tell me why ?
int static a=1;
int main()
{
static int a=10;
a++;
call();
return 0;
}
call()
{
printf("Weclome to IndiaBIX.com..! %d",a);
}
o/p :
Weclome to IndiaBIX.com..! 1
Please Tell me why ?
Vishwas said:
1 decade ago
Static variables are declared in a function so that other functions which access it from its local function cannot change the value. Only the local function can change its value. That's why its not used in function arguments.
Ravi said:
1 decade ago
Since when a function is called the arguments are pushed onto the stack for a particular function and according to the c protocols a static variables should be stored in the data sections.
Barath said:
1 decade ago
Acc to ANSI C standards we can not pass variables which are specified with storage class to function as arguments except the variables with the keyword register.
Shyamala krishnan said:
1 decade ago
Storage classes is important part of c language. WHENEVER we define any function in c program then we can call that in every defined class.
Sourav said:
1 decade ago
What will be the output if we remove static from the function argument in the above mentioned program. It is showing -347380. I mean how?
Dhananjai said:
1 decade ago
The default storage class of a formal arguments is Register. If the CPU registers are busy then it is stored in Stack section.
Rajsekhar said:
1 decade ago
It gives an error:.
Storage class specified for parameter i, j;.
Because we can not pass static variables to the functions.
Storage class specified for parameter i, j;.
Because we can not pass static variables to the functions.
Ramesh said:
1 decade ago
@apurva nigam.
Remember that, like any other local variable, a static variable cannot be referred to outside the function.
Remember that, like any other local variable, a static variable cannot be referred to outside the function.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers