Tuesday, July 14, 2009

What is an identifier in the C language?give brief theme with examples and what is relation with variables?

Basics of C LANGUAGE

What is an identifier in the C language?give brief theme with examples and what is relation with variables?
An identifier is a human-readable name for a symbol. Symbol is short for symbolic representation of a memory location and/or its contents. Since both code and data reside in memory, a symbol can represent either a function or [what's commonly called] a variable.





Some say that, in the purest sense, a function is a variable -- to a degree that's true, but it's not common usage. Usually when someone says "variable" they're talking about a data declaration... usually but not always. (Warning: I'm about to crank-up the "confusing stuff knob" to 11.)





It is possible to declare a variable of type pointer to function, as opposed to declaring an actual function, e.g.,





// actual function





int foo(int bar)


{


   return bar;


}





// define type "pointer to function that returns int,


// and accepts one int parameter"





typedef int (*LPFN_FOO)(int);





// declare a variable of type pointer to function [...], and assign


// the address of an actual function to it.





LPFN_FOO pFoo = foo;





// pFoo and foo can now be used interchangably





int a = pFoo(5);


int b = foo(5);





if (a == b)


   printf("it's true!");





The point of all this is that in common usage the terms "variable" and "function" refer to two inherently different concepts/constructs. But that not withstanding, we see that sometimes the line between them blurs (so badly it almost vanishes) -- which serves to bring home the fact that functions and variables are just symbols, that are referenced in source code by their identifiers.
Reply:identifiers are basically a name for either a variable or a function.





variables are declared like this:





int varName;





int is the type of the variable (what kind of data it can hold) and varName is the name of the variable.





The significance is that you use the identifier to represent the variable, so if you wanted to assign the above variable a value you would do it like this:


varName = 10;





identifiers can all so be the names of functions and are declared like this:





int funcName(int varName)


{


//code...


}





where int is the return type, or what kind of data that function will return when called. funcName is the identifier by which the function is called, and int varName is a paramater.





the site in my sources is a great C tutorial.


No comments:

Post a Comment