Breaking myth about C and C++

Breaking Myths about C and C++ – Part 1

Myth C++ is a high level Language

Reality The Answer is NO. Both C and C++ is middle level language. Though, C++ tends toward high –level languages but still it has some middle-level languages feature like pointers. If there are pointers, we can interact with address; we can do that in C++ too.

Myth High level languages are modern and middle-level languages are their ancestors.
Reality This is not at all true. FORTRAN is a high-level language and provides a higher degree of abstraction from C but it was developed earlier and has less features and less flexibility. FORTRAN, BASIC and PASCAL are high-level languages developed much earlier than C or C++. They have one thing common in them, they are non-structured. All the ancient languages are non-structured while modern languages are highly structured. Structured languages are Pascal, Ada, Java, C#, C++, C, Modula-2

Myth we cannot declare a variable with the name main

Reality Yes we can as main is not a keyword, but it will confuse compiler, therefore it is suggested that we should avoid using it.

int i;
void func1(void);
void func2(void);
int main(void)
i =100;
void func1(void)
int i =0;

void func2(void)
The output of this program will be

The output will be:

If global variable is declared again locally, the value of global variable in that scope changes locally according to changes in that scope but the changes are not reflected globally.

Myth There are two qualifiers that control how variables may be accessed or modified: const and volatile. A variable cannot be both const andvolatile at the same time.

Reality const prevents the variable’s value to be changed if explicitly specified by the program whereas volatile allows the variable’s value to be changed in ways not explicitly specified by the program. For example, a global address may be passed to the operating system’s clock routine and used to hold the real time of the system. In this situation, the value is not changed explicitly changed by the program. Therefore, system clock cannot be changed by any naïve user as well as it gets changed automatically.

Myth extern is another way to declare global variables and extern is used to declare the global variables and function from within the main function.

Reality It is true that when a variable is declared preceding with the extern specifier, it becomes global variable but it is used for different purpose. Suppose, a variable is declared extern, then it is not required to define the variable in the same file and there can be many declarations but only one definition. It is used to make compiler understand that the given variable has external linkages. Thus, compiler will not generate errors if the variable is not defined. extern can be used to declare functions and main functions from outside any function. It is usually used in header files. In C++, While providing linkage specification of function for other languages, extern definition should be written outside any function.

extern “Java”
void MyName( )
void ResourceAllocator( )


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s