Pointer Arithmetic
Pointer arithmetic means adding or subtracting values to the pointer variable. This is not the same as those simple arithmetic operations in normal variables. So how pointer arithmetic is different from simple arithmetic is explained below. Adding integer to pointer Suppose ‘p’ is a pointer to the ‘a’ variable. If we are adding n to…
Declaration and Assignment of Pointer
Now as we know meaning of & and * operators. We are going to declare and assign a pointer variable. Both are explained below. But the first most important thing about pointers is, “Data type of pointer and data type of variable (whose pointer we are creating) must be the same”. This means we want…
Pointer Address and Value
For pointers in C language, & and * operators are very important. To use a pointer, the understanding of both operators is a must. The meaning of both is as explained below. Meaning of & operator ‘&’ operator is called address operator. We can spell ‘&’ as “address of” whenever we are using it. This…
Introduction to Pointers
The C language is a very powerful language and its power is because of the pointer. With the right use of a pointer, we can make compact and very effective code using a pointer. The pointer is used for returning more than 1 value from any function, for DMA (Dynamic memory allocation), to access members…
Masking, Setting, Clearing and Testing of Bits
In the process of masking, we mask or filter bits of a variable. The variable is called the original value and the trail of bits that we are masking to the original value is called a mask. In this process, some bits of variables change and other bits remain as they are. We can do…
Shifting Operator
Left and Right operators are used to shift bits of a variable. First it converts that variable into its binary form and then shifts it to right or left. Using both operators, we can do multiplication and division of any variable with any number which is a power of 2. All these things we are…
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…