Duenice

C language tutorial for beginners

The c programming language is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C language tutorial for beginners is very important for students and developers.

c language
C Language

Introduction

Initially, the C language was developed to be used in the UNIX operating system. It inherits many features of previous languages such as B and BCPL. C language was easier to understand than B and BPCL. it can be used to perform low-level programming (eg drivers and kernels). It is commonly used to make hardware devices, OS, drivers, kernels, etc. For example, the Linux kernel is written in C.

Many later languages ​​have borrowed syntax/features directly or indirectly from the C language. The syntax of Java, PHP, JavaScript, Python, and many other languages ​​is mainly based on the C language. C ++ is almost a superset of the C language (there are some programs that can be compiled in C, but not in C ++).

Structure of a C Program

// First Programme to understand things
#include <stdio.h>                   // Header

int main() {                         // main()
int i=5;                             //Variable declaration
printf("Hello, World! %d \n",i);     // body
return 0;                            // Return
}

Header

The first and most important component is the inclusion of header files in the C program. A header file is a file with an extension. Containing C function declarations and macro definitions are shared between multiple source files. Header files are already stored in our computers which we use while writing programs.

Example:

Header Files
stdio.hDefining core input and output functions.
string.hDefining string handling functions.
stddef.hDefining several useful type and macros.
stdint.hDefining exact width integer types.
stdlib.hDefining numeric conversion function, pseudo-random network generator, and memory allocation.
math.hDefining common mathematical functions.

Syntex of a header file in C Language:

#include<stdio.h>

What is an array in c language?

An array is a variable that can store multiple values. For example, if you want to store 10 integers, you can create an array for it.

 int data[10];

 

Example: Program to input/output of 5 integers using arrays

// Program to take 5 values from the user and store them in an array
// Print the elements stored in the array
#include <stdio.h>

int main() {
int values[5];

printf("Enter 5 integers: ");

// taking input and storing it in an array
for(int i = 0; i < 5; ++i) {
scanf("%d", &values[i]);
}

printf("Displaying integers: ");

// printing elements of an array
for(int i = 0; i < 5; ++i) {
printf("%d\n", values[i]);
}
return 0;
}

Output

Enter 5 integers: 1
-2
3
4
5
Displaying integers: 1
-2
3
4
5

 

 

what is a string in c language?

The string can be defined as the one-dimensional array of characters terminated by a null (‘\0’).

Example: string program in C language

#include<stdio.h> 
#include <string.h> 
int main(){ 
char ch[11]={'H', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd', '
#include<stdio.h> 
#include <string.h> 
int main(){ 
char ch[11]={'H', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd', '\0'}; 
char ch2[11]="HelloWorld"; 
printf("Char Array Value is: %s\n", ch); 
printf("String Literal Value is: %s\n", ch2); 
return 0; 
}
'}; char ch2[11]="HelloWorld"; printf("Char Array Value is: %s\n", ch); printf("String Literal Value is: %s\n", ch2); return 0; }

Output

Char Array Value is: HelloWorld
String Literal Value is: HelloWorld

C language tutorial for beginners Learn and write a program.

Exit mobile version