Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

thumb rule for Variable in C

Status
Not open for further replies.

tom_hanks

Full Member level 5
Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,571
hi,

can any one suggest from his/her experience....

on what factor number of varialbes in one program depends....?


i am new with C, i am facing sevier prolem...
in my program there are somany variable, that it create confusion...

is there some thumb rule for good programming... ?
how to keep them low ?
 

To reduce confusion, divide your program into smaller functions, each doing a specific job.

Try to minimize the use of global variables. Within each function, use local variables. To communicate between functions, use function arguments instead of global variables.

Consider using structs to group related variables.

Use descriptive variable names, not cryptic abbreviations.

Add plenty of helpful comments.
 

Ther is no such thumb rule as such as how many variables a program should have.It depends on the complexity of the program and the way you structure a program.Learn the nuacnes of the C program and then use that to declare a particular variable as "static" or "extern" or "register".
Go through various C books on C or tutorials in Net.
 

You make the rules before start programming.
 

like said above, before you start the program, list out all the no of variables that you are going to need.. then group them together as per the function that they take part in... using these groupings plan for using functions by putting these variables as local instead of global.. just make calls with functions...

if you put some time into just this planning step instead of directly coding, you will save a lot of time and confusion later on..

also, while actual coding, immediately add detailed comments about what a particular variable is doing at a particular place... that will help you code faster and concisely with clarity too...

hope i've been of some help..

regards,
wiztronix
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top