Guys, this blog is for those who know the C language of Dennis Ritchie - for all those Software engineers out there who surely learned the basics the C language but not the mysterious parts of it. The C language has several things that we don't even know yet. I think may be the great Dennis Ritchie will be the only one who ever knew it!
Ok i will now stop my chats and start the investigation of the mysteries of C!
oh ! i did forgot to write the caption---- "Most of the things that you don't know about C!"
Ok i will now stop my chats and start the investigation of the mysteries of C!
oh ! i did forgot to write the caption---- "Most of the things that you don't know about C!"
C is not a block structured but structured programming language. Now the question arises what's the difference between structured and block structured? "A block structured language permits procedures or functions to be declared inside other procedures or functions." However, since C does not allow the creation of functions within functions, it cannot formally be called block structured isn't it?
We will discuss about 2 versions of C: the C89 and C99. The standard C89 consists of only 32 keywords, remember guys "our great C has only 32 keywords!" Hey why don't you guys give a shot in recalling those 32 key words! recalling more that 25 is the sign of a very talented programmer- many don't make it not even i couldn't come up with 20 key words even after using C for the past 4 years!
Here they are this time try to remember them it may be useful when you go for an Interview to form a career in IT sector.
auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
C99 also include the following 5 keywords too:
_Bool _Complex _Imaginary inline restrict
C's Memory Map
A C program (Compiled) creates and uses 4 logically distinct parts of memory.First: The memory that actually holds the programs executable code.
Second: Memory where the global variables are stored.
Third: The stack, used for a great many things while your program executes. It holds the return addresses of function calls, arguments to functions, and local variables.It will also save the current state of the CPU.
Fourth: The heap, a region of free memory that your program can use via C's dynamic memory allocation functions.
In C89, you must declare all local variables at the start of a block, prior to any "action" statements. However, in C99 you can declare local variables at any point within a block, prior to the first use(just as we do in JAVA).
The Four C Scopes
Standard C defines 4 scopes that determine the visibility of an identifier. They are summarized as:- File Scope: Starts at the beginning of the file and ends with the end of the file. It refers only to those identifiers that are declared outside of all functions. File scope identifiers are visible throughout the entire file. The variable with this kind of scope are known as the "Global Variables".
- Block Scope: Begins with the opening { of a block and ends with its associated closing }. However block scope also extends to function parameters in a function definition. Variables with block scope are local to their block.
- Function Prototype Scope: Identifiers declared in a function prototype; visible within the prototype.
- Function Scope: Begins with the opening { of a function and ends with its closing }. Function scope applies only to labels. A label is used as the target of a 'goto' statement, and that label must be within the same function as the goto.
Hexadecimal and Octal constants
C allows you to specify integer constants in hexadecimal or octal instead of decimal. A hexadecimal constant must consist of a 0x followed by the constant in hexadecimal. An octal constant begins with a 0.eg :-
int hex = 0x80 /* 128 in decimal*/
int oct = 012 /*10 in decimal*/
The Comma Operator
The comma operator strings together several expressions. The left side of the comma operator is always evaluated as void. This means that the expression on the right side becomes the value of the total comma-separated expression. For example:X = (Y=3,Y+1);
first assigns Y the value 3 and then assigns X the value 4. The parentheses are necessary because the comma operator has a lower precedence than the assignment operator.
The Dot(.) and the Arrow(->) Operators
The dot operator is used when working with a structure or union directly.
eg :- struct_name.element_of_structure = value;
The arrow operator is used with a pointer to a structure or union, that is, arrow operator is used with a pointer of pointer.
eg :- int **ptr;
int *abc;
struct student.roll_no = 5;
abc = &student.roll_no;
ptr -> abc;
now ptr will be containing the address of abc, while abc will be containing the address of student.roll_no.
Variable Length Arrays
In C89 the size of an array is fixed at compile time. However, this is not the case for C99, which adds a powerful new feature to arrays: variable length. In C99 you can declare an array whose dimensions are specified by any valid expression, including those whose value is known only at run-time. Only local arrays (that is those with block scope or prototype scope)can be of variable length.
eg :-
void newfunction(int x)
{
char str[x]; /* A variable length character array*/
/* . . . */
}
Friends i will be back soon with more mysterious parts of C language soon, until then wait!!!