Skip to main content

Posts

Showing posts with the label C

Volatile Qualifier in C : Explained by Example

                      V olatie qualifier can be used by keyword volatile in C/C++. You can define a variable as volatile by adding volatile qualifier just before data type.eg volatile int a; Volatile specifies a variable whose value may be changed by processes outside the current program. The meaning of outside of the current program may be Operating System or separate thread in case of multi threading processing. When we defines a variable as volatile, It does two things 1) The system always reads the current value of a volatile object from the memory location rather than keeping its value in temporary register at the point it is requested, even if a previous instruction asked for a value from the same object. 2) It stops Compiler to perform some optimizations. As we know that Compiler do some kind of optimizations on the source code before compilation. Below examples e...

Some Points About C Programming: Every Programmer Should Know

Some important points in C Programming Here I am writing some points about C programming which I acquired during my learning about programming. These points may help you to get more from the C language, and increase the curiosity to explore it wider. 1) You can not use return keyword in ternary operators(?,:) 2) You can't left the bracket empty of while and for loops like while() and for(); 3) if i=5; then i=i+(6,7,8,2,9); will assign i=5+9;Because of ',' operator association. 4) You can only apply the register specifier to local variables and to the formal parameters in a function. 5) If You declared too many register variables then compiler automatically transforms register variables into non register variables when the limit is reached. 6) You can't obtain the address of a register variable by using the & operator. 7) Register variable only for int and char type.It may support other types(not in Dev-C++5.3.0.4) but significa...

Dynamic memory allocation using malloc in C

If you are a beginner in programming it may be that you got some trouble to define an array of large size.As if you are trying to allocate an array of size (10^7===10000000) like                                       int a[10000000]; you must got an run time error called segmentation fault.To overcome these difficulties we use a malloc function to declare a run time memory. First we have to include header file "malloc.h" and then the following lines of codes. #include<malloc.h> int main() {      int *a;      a=(int *)malloc(sizeof(int)*10000000);  //equivalent to int a[10000000] without segmentation fault } If you want to declare a two dimensional array like.... int a[m][n]; Where m and n are very large number then write the following lines of codes. int main() {      int **a,i;      a=(int **)mall...