C Coarse
C Coarse
1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!");
5 return 0;
6}
Intro of C- lang
-> most of the programming langs like python, java, etc... are developed by using C
lang
-> C lang is very fast compared to python & java and other langs
-> C lang can be used in both apps & techs
-> the term "IDE" means "integrated development environment" & it is used to edit
and compile the code
-> for C, the most used IDE's are code::bolcks, visual code & others
-> web-based IDE can also be used but the functionality is limited
-> [note: in here, we're gonna use code::blocks, to use that, we should download
(mingwe. setup.exe) to install text editor and compiler]
-> we can use online compilers also
C lang syntax
-> syntax is nothing but the sentence in that, the grammar, and the protocol of
rules and regulations are followed
-> it runs if the code is running by using the right rules and regulations
-> in the above code, in line1 #include <stdio.h> is a header of the code
-> line2 will be blank to make the code readable
-> line3 will have a function main() which makes the sentence written in brackets
will be executed
-> line4 will have a function printf() which the sentence written in brackets will
be output
-> line5 will have a function return 0 which can help to end the main() function
-> line6 should have the closed bracket to complete the code
C lang output
-> to give space between two lines, we should include /n/n in the output written in
the execution code
example:
printf("HELLO WORLD"/n/nMY NAME IS SUSHANTH")
result:
HELLO WORLD
MY NAME IS SUSHANTH
-> like this, we have other 3 escape sequences. (/t), (//), (/")
/t functions help to output the 2 sentences in 1 line
example:
printf("HELLO WORLD/tMY NAME IS SUSHANTH")
result:
HELLO WORLD MY NAME IS SUSHANTH
// function helps to output the slash between 2 sentences
example:
printf("HELLO WORLD//MY NAME IS SUSHANTH")
comments of C lang
-> if the comment should be added in line with the syntax code, we should use the//
symbol.
-> if the comment is big, then we should start with the/* symbol and ends with the
*/ symbol
variables of C lang
-> variables help to insert the values like numbers, alphabets, decimals, and
others in the code
-> there are 3 types of variables that are mostly used in c lang
-> int variable is used to insert numbers
-> float variable is used to insert decimals
-> double variable is used to insert fractional values
-> char variable is used to insert alphabets like names, places, and others...
-> we can write the statement in a single line
example:
int Num1 = 15;
-> however, when u output the value, the printf function will not work. to make it
work, we should insert the specifiers into the brackets
-> there are 3 different and particular specifiers for the 3 different variables.
-> int- %d
example:
int Num1 = 30;
printf( %d, Num1 );
-> float- %f
example:
float Dec1 = 3.2;
printf( %f, Dec1 );
-> char- %c
example:
char Letter = G;
printf( %c, Letter );
-> if you want to add two numbers, then, we should use the + operator in the printf
function
example:
int x = 4,
int y = 7,
printf(%d, x + y)
-> if you have more than 2 variables, then we can write the statement in one line
using ",".
example:
int x = 4, y = 7, z = 30;
printf("%d", x + y + z)
C data types:
C constant
-> if you don't want to repeat the same value to represent the other one, then use
constant
example:
const int Num1 = 15;
Num1 = 10;
result:
error, Num1 is used only to represent the value 15
-> to understand, we may use uppercase for the value that we have used constant
example:
const char NAME = Sushanth;
C Operators
-> in the codes, we generally use the operators to add or subtract or divide or
multiply the values used in the codes
-> to add, w use the "+" operator
-> to subtract, we use the "-" operator
-> to multiply, we use the "*" operator
-> to divide, we use the "/" operator
-> to calculate the percentage, we use the "%" operator
-> to add the value by 1, we use the "++" operator
-> to subtract the value by 1, we use the "--" operator
-> to equal the value of the variable, we use the "=" operator
-> to add the value to the already existing value, we can use +=operator
-> to subtract the value to the already existed value, we can use -= operator
-> to multiply the value to the already existed value, we can use *= operator
-> to divide the value to the already existed value, we can use /= operator
C IF ELSE statement
-> to know wether a specified condition hes been execute or it's true, we should
use (if).
-> if the condition is false, to alternate the code, we should use (else).
-> if the first condition is false, to insert the new condition, we should use
(else-if).
-> to specify many alternative codes, we should use (switch).
-> example:
int time = 20;
if (time < 18) {
printf("Good day.");
} else {
printf("Good evening.");
}
-> if the code is huge, it will take much time to write a code
-> so, some changes are made by the senior programmers to write the IF ELSE
statement very quickly
-> example:
int time = 20; {
(time < 18) ? printf("good day") : printf("good evening");
return 0; }
C Switch statement
-> if we use IF-ELSE statement many times, it will take much time.
-> by using SWITCH statement, it will take less time.
-> example:
int = 30;
switch;
{
case x =
printf("april");
break;
case y =
printf("may");
break;
case z =
printf("june");
break;
default;
}
C while loop