943,907 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 807
  • C RSS
Aug 12th, 2008
0

Re: Hi Its Mithun

Expand Post »
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;
Last edited by m_banerjeein; Aug 12th, 2008 at 6:07 am. Reason: To make 1st question more clear
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
m_banerjeein is offline Offline
3 posts
since Aug 2008
Aug 12th, 2008
-1

Re: Hi Its Mithun

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...
Reputation Points: 12
Solved Threads: 3
Junior Poster in Training
Chaster is offline Offline
68 posts
since Jun 2007
Aug 12th, 2008
0

Re: Hi Its Mithun

Click to Expand / Collapse  Quote originally posted by Chaster ...
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??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
m_banerjeein is offline Offline
3 posts
since Aug 2008
Aug 12th, 2008
0

Re: I have few question

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Aug 12th, 2008
0

Re: I have few question

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
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Aug 13th, 2008
0

Re: Hi Its Mithun

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..........
Reputation Points: 5
Solved Threads: 3
Newbie Poster
gautam610 is offline Offline
13 posts
since Jul 2008
Aug 13th, 2008
0

Re: I have few question

BANERJEEEIN,

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

how hard is that?
Last edited by jephthah; Aug 13th, 2008 at 4:56 am. Reason: oops!
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: extract max-min value from every column in array
Next Thread in C Forum Timeline: fibonacci





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC