Wednesday, 31 May 2017

Pointer to Structure in C ~ GNIITHELP

Pointer to Structure Like we have array of integers, array of pointer etc, we can also have array of structure variables. And to make the use of array of structure variables efficient, we use pointers of structure type. We can also have pointer to a single structure variable, but it is mostly used with array of structure variables. struct Book { char name[10]; int price; } int main() { ...
Read More »

Pointer to Array in C ~ GNIITHELP

Pointer and Arrays When an array is declared, compiler allocates sufficient amount of memory to contain all the elements of the array. Base address which gives location of the first element is also allocated by the compiler. Suppose we declare an array arr, int arr[5]={ 1, 2, 3, 4, 5 }; Assuming that the base address of arr is 1000 and each integer requires two byte, the five element...
Read More »

Declaring and initializing pointer in C ~ GNIITHELP

Declaring a pointer variable General syntax of pointer declaration is, data-type *pointer_name; Data type of pointer must be same as the variable, which the pointer is pointing. void type pointer works with all data types, but isn't used oftenly. Initialization of Pointer variable Pointer Initialization is the process of assigning address of a variable to pointer variable. Pointer variable contains address of variable of same data type. In C language address...
Read More »

Pointers concept in C ~ GNIITHELP

Introduction to Pointers Pointers are variables that hold address of another variable of same data type. Pointers are one of the most distinct and exciting features of C language. It provides power and flexibility to the language. Although pointer may appear little confusing and complicated in the beginning, but trust me its a powerful tool and handy to use once its mastered. Benefit of using...
Read More »

Unions in C ~ GNIITHELP

Unions in C Language Unions are conceptually similar to structures. The syntax of union is also similar to that of structure. The only differences is in terms of storage. In structure each member has its own storage location, whereas all members of union uses a single shared memory location which is equal to the size of its largest data member. This implies...
Read More »

typedef in C ~ GNIITHELP

typedef typedef is a keyword used in C language to assign alternative names to existing types. Its mostly used with user defined data types, when names of data types get slightly complicated. Following is the general syntax for using typedef, typedef existing_name alias_name Lets take an example and see how typedef actually works. typedef unsigned long ulong; The above statement define a term ulong for an unsigned long type. Now this ulong identifier can...
Read More »

Introduction to Structure in C ~ GNIITHELP

Introduction to Structure Structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store collection of similar datatypes while structure can store collection of any type of data. Structure is used to represent a record. Suppose you want to store record of Student which...
Read More »

Passing Array to function in C ~ GNIITHELP

Passing Array to Function Whenever we need to pass a list of elements as argument to the function, it is prefered to do so using an array. But how can we pass an array as argument ? Lets see how to do it. Declaring Function with array in parameter list There are two possible ways to do so, one will lead to call by value and the other is used to perform call be reference. We can either have an array in parameter.int sum (int arr[]); Or, we can have a pointer in the parameter list,...
Read More »

Types of Function calls in C ~ GNIITHELP

Types of Function calls in C Functions are called by their names. If the function is without argument, it can be called directly using its name. But for functions with arguments, we have two ways to call them, Call by Value Call by Reference Call by Value In this calling technique we pass the values of arguments which are stored or copied into the formal parameters of functions. Hence, the original values are unchanged only the parameters inside function changes. void calc(int...
Read More »

Functions in C ~ GNIITHELP

Functions in c A function is a block of code that performs a particular task. There are times when we need to write a particular block of code for more than once in our program. This may lead to bugs and irritation for the programmer. C language provides an approach in which you need to declare and define a group of statements once and that can be called and used whenever required. This saves both...
Read More »