#include<stdio.h>
int main(){
return 0;
}
This is the syntax(Boilerplate code)
printf(): printf() function for used to show the output.
printf("lapmos.com")
scanf(): scanf() function for used to take the input from users.
scanf("format_specifier", &variable);
A comment is not executed by the compiler. The comments is used for the increase the readability. In c programming language two types of comments.
// This is single Line Comment
/* This is
Multiple line
comment
*/
Datatype is the type of data to declare the variable.
int variable_name;
char var;
float var_name;
double variable_name;
void
It is a sequence of characters starting with a backslash, and it doesn't represent itself when used inside string literal.
// Beep / Alarm: It produce the beep sound.
\a
// backspace: Add Backspace
\t
// new line: Add new line
\n
// carriage return
\r
// Tab: Gives the tab space
\t
// Backslash: Add backslash
\\
// Single Quote: Add single quotation mark.
\'
// Question Mark: Add Question mark
\?
// Octal Number: It represents the value of an octal number.
\nnn
// Hexadecimal Number: It represents the value of an Hexadecimal number.
\xhh
// Null: The null character is usually used to terminate a string.
\0
Conditional statement is used to perform the logical operation in program.
// if statement
if(/* condition */){
/* statement; */
}
// if-else statement
if(/* condition */){
/* statement*/
}
else{
/* statement */
}
// if-else-if-else statement
if(/*condition*/){
/* statement */
}
else if(/* condition */){
/* statement */
}
else
{
/* statement */
}
// switch statement
switch(/*expression*/){
case 1 :
/*statement*/
break;
case 2 :
/* statement */
break;
....
default :
/* default statement */
}
loop is used for, the line of code execute repeatedly then programmer used loops.
// for loop in c
for(/*initialization*/ ; /*condition*/; /*increament/decrement*/)
{
/* code*/
}
// while loop
while(/*condition*/){
/*code*/;
}
// do while loop
do{
/* code */
}while(/*condition*/);
// break statement: break keyword inside the loop is used to terminate the loop.
break;
/* continue statement: continue keyword skips the rest of the current
iteration of the loop and returns to the starting point of the loop. */
continue;
Function are used to divide the program in pieces and used function many times in our program.
// function definition
return_type name_function(data_type parameter ...){
// code of the function
}
Recursion is when a function calls itself to solve the problem. Which function is calls iteself called the recursive function.
void fun(){
... ... ..
fun();
... ... ..
}
Pointer is the variable which contains the address of the another variable.
data_type = *variable_name;
Array is the collection of the same datatypes.
data_type array_name[array_size];
Access array element
arr[index_no];
A string is a 1-D character Array terminated by a null character("\0").
// declaration
char string_name[string_size];
gets() function: It allows to enter the multi-word string.
gets("lapmos.com");
puts() function: It used to show the string.
puts("lapmos.com");
strlen() function: It is used for to calculate the length of string.
strlen(string_name);
strcpy() function: it is used for copy the string to another one.
strcpy(destination, source);
strcat() function: It is used for concatenate two string.
strcat(first_string, second_string);
strcmp() function: It is used for compare two string.
strcmp(first_string, second_string);
The structure is a collection of different types of variable in a single. Define structure means creating a new data type.
// Syntax
struct structure_name
{
datatype member1;
datatype member2;
... .... ...
};
typedef keyword: typedef function allows user to provide alternative names for the primitive and user-defined data type.
typedef struct structure_name
{
datatype member1;
datatype member2;
... ... ...
}name;
OR
struct structure_name
{
datatype member1;
datatype member2;
... ... ...
};
typedef structure_name new_name;
File handling in c enables us to create, update, read and delete the files stored on the local file system through our C program.
// File Pointer
FILE *filepointer;
// Opening a file: It is used to open file in C
filePointer = fopen(filename.txt,w);
// fscanf() function: It is used to read the content of file.
fscanf(FILE *stream, const char *format, ...);
// fprintf() function : It is used to write content into the file.
fprintf(FILE *fptr, const char *str, ...);
// fgetc() function : It reads a character from a file opened in read mode.
fgetc(FILE *pointer);
// fputc() function : It writes a character to file opened in write mode.
fputc(char, FILE,*pointer);
// Closing a File : It close the file.
fclose(filePointer);
The concept of dynamic memory allocation in c language enables the C programmers to allocates memory at runtime.
// malloc() function
ptr = (TypeCast*)malloc(size());
// calloc() function
ptr = (TypeCase*)calloc(n,size);
// free function
free(ptr);
// realloc() function
ptr = realloc(ptr, x);
Comments
Oops!