473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

About Variable declaration in C

2
when will be the memory allocated for a variable?when it declared or defined
Sep 6 '06 #1
6 3599
when will be the memory allocated for a variable?when it declared or defined
The memory will be allocated for a variable when it is declared.
Sep 6 '06 #2
hi memory to a veriable allocated the time it is declered
i.e. int a[100] allocates 100 integer memory locations to this array
even if u r not using all.

thats why the concept of dynamic memory allocation came into picture to utilise the memory efficiently.
Sep 6 '06 #3
memory is allocated only when it is defined,
this is given in yashvant kanetkar's c book
Sep 6 '06 #4
What do you mean by variable declaration and variable definition?

Even if we declare a variable like

int a;

still it has some value (which we are saying normally as garbage).

So I think in terms of variable, definition and declaration do not matter.

Yes but in terms of functions, declaration means prototype and definition means the actual code of the function. Here only definition will occupy the space.

In case of structure also, unless you declare a variable of that structure it does not take any space in memory.
Sep 6 '06 #5
when will be the memory allocated for a variable?when it declared or defined
Memory will be allocated only when a variable is defined.
When a variable is declared it just tells the attribute of the variable either int, float or char..... to the compiler and no memory will be allocated.
Jul 24 '07 #6
JosAH
11,448 Expert 8TB
The distinction between declaration and definition does matter: a declaration
just tells the compiler that a variable exists somewhere. It's up to the linker to
find it and adjust whatever it has to adjust. A definition tells the compiler "here
is the variable; do something with it, like allocating storage for it". A definition
whithout a preceeding declaration is a declaration (and a definition) by itself.
A 'tentative' definition is a declaration that *can* be a definition, as in 'int x;'

Multiple tentative definitions are considered declarations. The 'extern' keyword
isn't obsolete.

kind regards,

Jos
Jul 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the...
5
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
6
by: Chad | last post by:
In the following code snippet, I declare the variable val as float in the calc.h header file, and define it as int in test.c. The question is, when I compile this with full warnings, I get no...
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
9
by: Lalatendu Das | last post by:
I have seen a header file in which one structure is defined with extern declaration in a header file and declared one variable of that structure in one C-file. The code goes as mentioned below . I...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
16
by: Haskell Prelude | last post by:
Hello Friends - Can anyone answer these C questions? 1. What is the effect of making an internal (local) variable static? 2. What is the effect of making an external (non-local) variable...
7
by: David Mathog | last post by:
I accidentally did this the other day (it was a lot less obvious in the much longer actual program, hundreds of lines are omitted): ----------------------------------------------------------...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.