Basic syntax and functions from the C programming language.
#include <stdio.h>
int main()
{
return(0);
}
It is used to show output on the screen
printf("Hello Kashmir!");
It is used to take input from the user
scanf("placeholder", variables)
A comment is the code that is not executed by the compiler, and the programmer uses it to keep track of the code.
// It's a single line comment
/* It's a
multi-line
comment
*/
The data type is the type of data
Typically a single octet(one byte). It is an integer type
char variable_name;
int variable_name;
A single-precision floating-point value
float variable_name;
A double-precision floating-point value
double variable_name;
Represents the absence of the type
Void
\a
\b
\n
\t
\''
Conditional statements are used to perform operations based on some condition.
if (/* condition */)
{
/* code */
}
if (/* condition */)
{
/* code */
}
else{
/* Code */
}
if (condition) {
// Statements;
}
else if (condition){
// Statements;
}
else{
// Statements
}
It allows a variable to be tested for equality against a list of values (cases).
switch (expression)
{
case constant-expression:
statement1;
statement2;
break;
case constant-expression:
statement;
break;
...
default:
statement;
}
Iterative statements facilitate programmers to execute any block of code lines repeatedly and can be controlled as per conditions added by the programmer.
while (/* condition */)
{
/* code */
}
do
{
/* code */
} while (/* condition */);
for (int i = 0; i < count; i++)
{
/* code */
}
break keyword inside the loop is used to terminate the loop
continue keyword skips the rest of the current iteration of the loop and returns to the starting point of the loop
break;
continue;
Functions are used to divide an extensive program into smaller pieces. It can be called multiple times to provide reusability and modularity to the C program.
return_type function_name(data_type parameter...){
//code to be executed
}
void recurse()
{
... .. ...
recurse();
... .. ...
}
Pointer is a variable that contains the address of another variable,
Declaration
datatype *var_name;
An array is a collection of data items of the same type.
data_type array_name[array_size];
A string is a 1-D character array terminated by a null character ('\0')
It allows you to enter multi-word string
It is used to show string output
char str_name[size];
gets("string");
puts("string");
strlen(string_name);
It is used to calculate the length of the string
strcpy(destination, source);
It is used to copy the content of second-string into the first string passed to it
strcat(first_string, second_string);
It is used to concatenate two strings
strcmp(first_string, second_string);
It is used to compare two strings
The structure is a collection of variables of different types under a single name. Defining structure means creating a new data type.
struct structureName
{
dataType member1;
dataType member2;
...
};