Hi All

Guys few quick questions on C..

1. What does "static void <function_name>(argument1,argument2)" means..

2. Whether this would give a compilation error if i write this piece of code...

int a =1 , b=2,c=3 ;
(a=b)=c;

Recommended Answers

All 6 Replies

Hi All

Guys few quick questions on C..

1. What does "static void <function_name>(argument1,argument2)" means..

2. Whether this would give a compilation error if i write this piece of code...

int a =1 , b=2,c=3 ;
(a=b)=c;

Well,
static means (at least in Java, but I think it's the same) that you don't need to create an instance of that class, you can access that method directly: ClassName.methodName([params]).
void means that your function is actually a "procedure" and will not return any value
arguments are the values you pass to your function

The piece of code is illegal in Java, I don't know whether it's correct in C. sorry...

commented: its totally unhelpful to give Java answers to C questions. stay in the java section if you dont' know C -1

Well,
static means (at least in Java, but I think it's the same) that you don't need to create an instance of that class, you can access that method directly: ClassName.methodName([params]).
void means that your function is actually a "procedure" and will not return any value
arguments are the values you pass to your function

The piece of code is illegal in Java, I don't know whether it's correct in C. sorry...

Well this is a piece of code in C only...

1. I have only the problem in understanding the return type.

Is this that function is static to the file where i will be using??

1) static is a scope operator that limits the scope of the function to the *.c file in which it is declared. If you have two *.c files, each file could contain a function with the same name as long as the function is declared static. IMO its poor programming to have two functions like that, but it is possible.

2) compile it and find out what happens.

i know you are asking about functions, but an important thing about static, is that when you scope a local variable as such, it will retain its value across repeated calls to the function where it is declared. this is very important when creating functions, espeically if they are intended to be imported into larger projects.

you can also make a static global variable that will retain its value and be visible to all functions with the *.c file, but no functions anywhere else, much like how DRAGON described the static-scoped function

2) This is an L-value error that u have to put a reference that have a legal address at the left side of assignment operator at the equal sign..........

BANERJEEEIN,

what DRAGON said... compile it and find out.

how hard is that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.