answersLogoWhite

0

What is definition and declaration in C?

Updated: 8/11/2023
User Avatar

Willess

Lvl 1
12y ago

Best Answer

int x;
float x;
char x;
double x;
long x;
long long x;
short x;
unsigned int x;
unsigned float x;
unsigned double x;
signed char x;
unsigned long x;
unsigned long long x;
int *x;
float *x;
char *x;
double *x;
long *x;
long long *x;
int x[100];
typedef struct rect {
int left;
int top;
int right;
int bottom;
};
int main(int argv, char* argc[]) {
return 0;
}
That enough for you?

Well, these are definitions, declarations are like these:

extern char x;
int main (int argc, char **argv);

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

declaration is like a promise that somewhere else the thing in question will be actually defined.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is definition and declaration in C?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When variable in c gets memory After declaration or initialization?

Definition. Example: extern int x1; /* declaration */ int x2; /* definition */ int x3= 2; /* definition with initialization */


What is True in C programming A multiple fn definitions and multiple declarations B 1 declaration multiple fn definitions C 1 fn definition 1 declaration D multiple declaration 1 definition?

A function's declaration must be visible within every translation unit that uses that function, thus multiple declarations are permitted. To ensure consistency across all translation units that use a function, the declaration is usually placed in a header which can be included wherever it is needed. Formal arguments need not be named in a declaration (they do not form part of the function's prototype), but named arguments can provide better documentation and need not match the names used by the definition, or indeed by any other declaration of the same function. Note that a definition is itself a declaration, thus if a function is declared (but not yet defined), there has to be at least two declarations because the function must be defined somewhere. The "one definition rule" (ODR) implies there can only ever be one definition of a function, however multiple definitions are permitted provided those definitions appear in different translation units and are token-for-token identical (including the names of formal arguments). Being token-for-token identical means there is only one definition. Thus the correct answer is D: multiple declarations with one definition.


How do you write a function in Turbo C Plus Plus?

// declaration: return_type function_name([argument_type_1[=value][, argument_type_2[=value][, ...]]]); // definition (function signature must match declaration): return_type function_name([argument_type_1 argument_name_1[, argument_type_2 argument_name_2[, ...]]]) { // implementation } In the case of separate declaration/definition, the definition file must include the file that contains the declaration unless they are both in the same file. If the function is a template function, both the declaration and the definition must be visible to the compiler BEFORE it can be used (thus they must both be in the same file). For all other functions other than inline expanded functions, only the declaration need be visible. Note that the definition is also a declaration, however default values must be omitted and all arguments must be named. The declaration arguments may also be named but they needn't match those in the definition (the definition names are the ones actually used). Alternatively: // combined declaration and definition: return_type function_name([argument_type_1 argument_name_1[=value][, argument_type_2 argument_name_2[=value][, ...]]]) { // implementation } Functions that are defined in the declaration are impicitly inline expanded. Functions that are defined separately must be prepended with the inline keyword in the definition, and the definition must be visible to the compiler BEFORE the function can be used. Functions that do not return a value must return void. If any other return type is specified, the function must explicitly return that type via all return paths. The main function must return an int, however return(0) is implied if not specified in the final statement.


What is the syntax of function?

Function declaration, definition, or calling? Pick one.


In c plus plus Who tells the compiler that a specific class will be declared later in the program?

A forward declaration. However forward declarations can only be used when the class is used as a pointer or reference prior to its definition, otherwise it must be defined before it is used. class A; // forward declaration class B { A& data; // reference to class that has yet to be defined }; class A {}; // definition

Related questions

What is the difference between declaration and a definition in c plus plus?

A declaration is an incomplete type whereas a definition is a complete type.


When variable in c gets memory After declaration or initialization?

Definition. Example: extern int x1; /* declaration */ int x2; /* definition */ int x3= 2; /* definition with initialization */


What is the difference between declaration and a definition in C with small example?

declaration examples:int main (void);extern int somevariable;definition examples:int main (void) { puts ("Hello world"); return 0; }int somevariable;


C programming language bsc it notes?

different between defining value definition section and defining value declaration section


What is the difference between declaration and definition?

definition: the meaning or description of person/place/thing declaration: taking a stand


What is the difference between declaring variable and initializing variables?

Actually, there is a third step, call definition. Declaration is a statement to the compiler of what type an identifier is, definition is the allocation of memory for that identifier, and initialization is the assignment of an initial value to that identifier. Usually, declaration and definition are done together, but you can also add initialization in that step if desired. int a; /* declaration and definition */ a = 1; /* initialization */ int a = 1; /* declaration, definition, and initialization */ For the case of seperate declaration and definition, consider the struct... struct _mystruct { int a; }; /*declaration */ struct _mystruct mystruct; /* definition */ struct _mystruct { int a; } mystruct; /*declaration and definition */ Note: To be more precise: struct _mystruct; /* struct declaration */ struct _mystruct { int a; }; /* struct definition */ typedef struct _mystruct MYTYPE; /* type definition */ extern struct _mystruct mystructvar; /* variable declaration */ struct _mystruct mystructvar; /* variable definition */ struct _mystruct mystructvar = {7} ; /* variable definition with initialization */ struct _mystruct { int a; } mystruct; /* struct definition and variable definition */ extern struct _mystruct { int a; } mystruct; /* struct definition and variable declaration */


What is variable definition in c language?

variable definition means to declare the variable with its value. for example:- int i=10; this statement is a combination of declaration of integer i and assign its value to it,so it is a definition statement Note: assigning a value is not essential.


What is True in C programming A multiple fn definitions and multiple declarations B 1 declaration multiple fn definitions C 1 fn definition 1 declaration D multiple declaration 1 definition?

A function's declaration must be visible within every translation unit that uses that function, thus multiple declarations are permitted. To ensure consistency across all translation units that use a function, the declaration is usually placed in a header which can be included wherever it is needed. Formal arguments need not be named in a declaration (they do not form part of the function's prototype), but named arguments can provide better documentation and need not match the names used by the definition, or indeed by any other declaration of the same function. Note that a definition is itself a declaration, thus if a function is declared (but not yet defined), there has to be at least two declarations because the function must be defined somewhere. The "one definition rule" (ODR) implies there can only ever be one definition of a function, however multiple definitions are permitted provided those definitions appear in different translation units and are token-for-token identical (including the names of formal arguments). Being token-for-token identical means there is only one definition. Thus the correct answer is D: multiple declarations with one definition.


What is the definition for factors of productions?

th declaration of independence


What is the difference between declaration and initialization?

Perhaps an example will help. extern int value; /* declaration */ int value; /* definition */ int value= 20; /* definition with initialization */


How do you write a function in Turbo C Plus Plus?

// declaration: return_type function_name([argument_type_1[=value][, argument_type_2[=value][, ...]]]); // definition (function signature must match declaration): return_type function_name([argument_type_1 argument_name_1[, argument_type_2 argument_name_2[, ...]]]) { // implementation } In the case of separate declaration/definition, the definition file must include the file that contains the declaration unless they are both in the same file. If the function is a template function, both the declaration and the definition must be visible to the compiler BEFORE it can be used (thus they must both be in the same file). For all other functions other than inline expanded functions, only the declaration need be visible. Note that the definition is also a declaration, however default values must be omitted and all arguments must be named. The declaration arguments may also be named but they needn't match those in the definition (the definition names are the ones actually used). Alternatively: // combined declaration and definition: return_type function_name([argument_type_1 argument_name_1[=value][, argument_type_2 argument_name_2[=value][, ...]]]) { // implementation } Functions that are defined in the declaration are impicitly inline expanded. Functions that are defined separately must be prepended with the inline keyword in the definition, and the definition must be visible to the compiler BEFORE the function can be used. Functions that do not return a value must return void. If any other return type is specified, the function must explicitly return that type via all return paths. The main function must return an int, however return(0) is implied if not specified in the final statement.


Automatic inline in c plus plus?

The C++ compiler will implicitly (automatically) mark functions for inline expansion whenever you define a function within its own declaration. If functions are declared and defined separately (even in the same file) then they are not implicitly marked for inline expansion. To enable inline expansion for these definitions, you must explicitly mark the definition (not the declaration).