This is a discussion on Declaration and definition in C++. within the C and C++ Programming forums, part of the Software Development category; Differentiate between declaration and definition in C++. A declaration introduces a name into the program; a definition provides a unique ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Differentiate between declaration and definition in C++. A declaration introduces a name into the program; a definition provides a unique description of an entity (e.g. type, instance, and function). Declarations can be repeated in a given scope, it introduces a name in a given scope. There must be exactly one definition of every object, function or class used in a C++ program. A declaration is a definition unless:
A definition is a declaration unless:
__________________ J.Vijayanand |
| Sponsored Links |
| |||
| Difference between declaration and Definition Declaration It just indicate the presence of a variable or memberfunction and ends with a semi-colon. For eg; int i;-->declaration add();--->declaration Definition It explains the behaviour of the function.If it is a variable it defines its value. For eg: int i=2;--->It is definition of a variable add()--------->Definition { int a=2,b=3,c; c=a+b; } |
| |||
| It is really simple to differentiate between a definition and declaration. Good examples you have provided, but a starter might really be confused at the beginning with these terms. |
| |||
| Hai, The above declaration is correct. If u cant understand,refer this... Consider a normal C++ program, class a { add();->Function call } void a:add()->Function Definition { int c1;->declaration of a variable cout<<"Enter a1"; cin>>a1; cout<<"Enter b1"; cin>>b1; c1=a1+b1;->Definition of a variable cout<<c1; } This is incase of C++ Program.. If u use C,then void main() { int c;->Declaration(Since u didnt assigned value) c=add();->(Here c is defined(i.e..,Value is assigned through function) printf("%d",c); } int add() { int a1,b1,c1; printf("Enter two numbers"); scanf("%d%d",&a1,&b1); c1=a1+b1; return(c1); } In the above function the value returned by 'add()' is assigned to 'c' |
| |||
| hi poornima, i think your definition is too complex... . i think kingmaker has done a clear job, its more than enough to explain the context
__________________ SeeSamJagan- Sky is not the "LIMIT", Death is not the END, There is still something beyond.... |
| |||
| int i; struct rat { public: int num; int denom; }; int inc(int count) { count = count + 1; } However the following are only declarations. extern int i; struct rat; extern int inc(int count); |
| |||
| declaration: its mean the variables or functions have been just created, yet they are not ready for use. example int i; int j; void doAnything(); Definition if we need to use those functions and variables we must initialize the variables or build the function. the process to initialize or building functions called definitions.
__________________ Thanks & Regards, Jegan CBK "We will either find a way, or make one!” |
| |||
| Thanks guys! I was really looking for this topic on the net, and thank God I found this thread. I had my confusions on how to declare the variables. babyProducts-online / Great education Deals |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Gah... definition help!! | vadivelanvaidyanathan | Software Testing | 0 | 01-23-2008 03:46 AM |
| Definition of Ciphers & types of Ciphers? | H2o | Other Web Programming Languages | 1 | 07-22-2007 10:25 PM |