C Programming For Gate 2023 In One Blog With Examples

Rate this post

In this blog, I will be covering all the important topics that every GATE Aspirant should know before writing a gate examination.

Introduction To C programming

C programming is a platform-dependent programming language used to create programs for general-purpose software or to create a compiler kind of thing. Learning C Programming builds your logic and clear’s the basic working of any programming language by understanding the fundamental’s of c programming we can achieve the ability to think like a compiler and will be able to understand how the compiler will compile our code to achieve the intended requirements. And one thing to know here is C programming is a compiler-based language. So let’s discuss some of the fundamentals of C programming.

Datatype In C Programming

Whenever we are going to learn new programming here we are always using their default datatypes to write programs, So knowing datatypes is a really important part of any programming language and how they are declared.
Default datatype is also known as pre-defined datatypes which are present inside C programming and we can use that datatype to write programs, So below are all of the datatypes in a c programming language.
1. int: used to declare integer datatype. eg: int a;
2. char: i.e used to declare characters datatype). eg: char a;
3. float: used to declare rational datatype which contains floating values like 2.2). eg: float a;
4. double: used to declare bigger rational values which cannot be held by float datatype for example float is of 4 bytes and double is of 8 bytes so double can store more values than float datatypes. eg: double a;
5. long: used to declare that integer datatype can hold a bigger storage size than int datatype. for example, int is 2 bytes which mean an integer can hold at most 2 bytes of data and float is 4 byte which can hold at most 4 bytes of data and not more than that. eg: double a;
6. Array: used to declare array datatype which holds values of similar datatype and storage will be contiguous memory is allocated. eg: int a[100]; which holds 100 integer data.

The above datatypes, are known as predefined datatypes, and most of the time we are happy with these datatypes but for many reasons, we need some new datatype or we can say create our own datatype which can help us achieve our requirements, So this datatype is known as a user-defined datatype. Below is the datatype to create a user-defined datatype in c programming.

  1. Struct:- Struct stands for structure and this is used to define a group of datatypes which can be similar or different datatypes, for example, we want to store students’ data but there is no existing datatype that stores students’ data. So using the struct keyword we can do that.
    struct student {
    int roll;
    char[] name;
    char[] class;
    }
    2. Union:- Union slightly differs in storage as compared to a struct. In struct every datatype occupies its space like in the above example int 2 bytes, char 1 byte, char 1 byte then total space will be allocated is of 4 bytes, but in union storage space allocated will be equal to max datatype like in this case integer is max i.e 2 bytes will be allocated.

Memory Structure In C Programming

Every process needs a memory and mainly their are two types of memory ROM and RAM, For Rom we means that the data/program is stored which is not in the running state and when we run the program it will be stored in the ram and the processing is done in the form of stack which is also known as stack activation record. To Know more about stack activation record we need to understand compiler design topics.

Pointer In C Programming

Pointer is a very useful thing in c programming because in c programming we follow passed by value in function instead of pass by reference. In the case of passed by value we are just passing constants instead of the variable and whatever changes will do on that formal parameter will not impact calling function variable.
So to achieve that we use pointer’s in c programming.
Pointer means pointing to a particular location where the value is present and to declare pointer in c programming we use ‘*’ operator which is also know as indirection operator. And this * operator is also referred as value at or content at. let take an example.
int *a; (this is just declaring pointer and nothing else) .
int b = 40;
a = &b; (here we just passing the address of b and nothing else, So ‘a’ as a pointer will hold address of b)
printf(“%d”, a); // it will print address of b
printf(“%d”, *a); // note here ‘a’ holds address of b so content at a will print 40.

Arrays In C Programming

Arrays is a very useful way to store values in one by one manner also known as storing values in a contiguous memory in which accessing index starts from 0 to maxvalue-1.
for example:
int a[100]; // after reading this compiler will allcoated 100 integer storage in the memory i.e 0 to 99.
printf(“%d”,a) // this will print the starting/base address.
printf(“%”,a[0]) // this will print value at that base address and a[0] can also be written as ‘ *a ‘

formula to access the data in arrays for any datatype using pointers can be written as follow:-
*(baseaddress + index X sizeof(datatype));
for example for int a[100] the formula can be written as *(100 + 2(2)) here 100 is a base address and 2 in a index number and 2 is interger size in bytes.

Function In C Programming

Function In C programming is very useful to create bigger task into subtask and to declare function we need follow syntax i.e returntype functioname(parameters);
int add(int a, int b){
int sum = a+b;
return sum;
}
add(1, 2);
note:- here int a ,int b is formal parameter which just holding the value 1 and 2 and nothing else. and add(1,2) here 1 and 2 is actual parameter.

Storage Classes In C Programming

Storage Classes in C programming is really important and some of the storage classess is as followed:
1 Auto:- auto stands for automatic which means that whenever we declare any dataype but not declare any storage class with that then it will be declared as auto and by default it will hold some random value if not intialize. Automatic variables are destoryed when function is destroyed. block is ended.
2. Extern:- extern stands for external variable and it is used to access externally declared value so whenever we want to use the external variable then we have to declare it with extern.
3. Register:- Register is used to declare register varaibles and this register variables are access in any function of that program.
4. Static:- Static is used to declare static variable and this static variables are commonly used to store that value which can used outofscope inshort static variable preserves their value. and also they are not initailzed in the other scope.

Leave a Comment

Scroll to Top