This is a discussion on Variable Declaration within the C and C++ forums, part of the Programming Talk category; I am confused with the declaration of variable passed as argument to a function.I tried a sample C program ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Variable Declaration
I am confused with the declaration of variable passed as argument to a function.I tried a sample C program given below:
#include <stdio.h> main() { int a=500,c; c=sampel(a); printf("c=%d",c); } sample(t) { int t; t=t+10; return(t); } The above program gave me error. Is it that I have to declare t before the opening braces of defining the function sample? What is the reason for this? |
|
|||
|
The error you would have got is Re-declaration of t in function sample. Am I right? The reason for this is you have not declared the variable t before the opening brace of function sample().So by default it is assumed as integer variable. But again after the opening brace you have declared again variable t which causes the compiler to throw the error message as re-declaration of
variable t. Remove the declaration and try out and always it is best to declare variables before the opening braces of function calling. |
![]() |
| Thread Tools | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-15-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:01 AM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 07:00 AM |
| comp.lang.c Answers (Abridged) to Frequently Asked Questions (FAQ) | Steve Summit | Tech FAQ | 0 | 05-15-2004 07:00 AM |
| Smalltalk FAQ (v.1.0) | Vikas Malik | Tech FAQ | 0 | 04-17-2004 08:27 AM |