Compliment Operator

This is a unary operator. This means it needs one variable to do the operation. This operator first converts variables in binary then does complement operation and at the end, it converts the result to its previous data type. Let us see what happens when we do bitwise complement operation with any two bits. Syntax…

Logical Operator

Till now we were using bytes of any data but C provides the facility to do the operation with an individual bit of a byte. This we can do using the bitwise operator. There are 6 bitwise operators and those are listed below. These operators can work with int, char data types. Operator symbol Operator…

Typedef for Portability

Typedef is used to change the name of any standard library data type. We are using int data type. If we want to change the name of int to any other name then we use typedef. In this, wherever we want to write keyword “int” data type then instead of keyword “int” we use the…

Bit fields in Struct

In structure, there are many variables. Some of them are not even used. And some of them are used partially. This means if there is a variable of int data type then it occupies 2 bytes in memory. But suppose if the value which we are storing in it is of only 1 byte so…

Struct Copy & Comparison

Copy structure means copying all variables of a structure to another structure. Structure comparison means comparing all variables of a structure to another structure. Structure Copy We can copy the structure variable directly using ‘=’ sign, only if both source and destination variables are of the same structure. Means both structure variables must be variables…

Allocation of Memory

Structure storage in memory The members of a structure are stored consecutively in the memory. The size of members may differ from one machine to machine. But the important point to note about member storages is, they are stored consecutively in memory. Example program to understand structure member storage In the below example, there is…

Return Structure through functions

“Returning structure through function” statement has 2 meanings: Returning structure variable through function, Returning structure member through function. We are going to understand both one by one. Returning structure variable through function Syntax of returning structure variable through function is as listed below for function declaration, call, and definition.  Function declaration struct  <structure name>  <function…

Passing Struct through functions

“Passing structure through function” statement has 2 meanings: Passing structure variable through function, passing structure member through function. We are going to understand both one by one. Passing structure variable through function In this, we pass the variable of structure as an argument of a function. Syntax of the same is listed below for function…

Unions

Whatever we studied about the structure and whatever is explained after this topic about structure is the same for union. We can use union, wherever we are using structure but there are some differences between union and structure and those are explained below. Below differences we have to keep in mind while making a program…

Array of Struct

If we want many variables of the same structure then we can make an array of structure variables. Because it is time consuming to make many variables of the same structure. Let us understand this by an example. In the below example, structure str has 3 variables: stu1, stu2. stu3, struct str{ int roll_no; float…