0% found this document useful (0 votes)
29 views6 pages

C Coarse

The document provides an overview of the C programming language, including: 1) C was developed by Dennis Ritchie and used to create the UNIX operating system. It is faster than languages like Python and Java. 2) C++ is an extension of C that supports classes and objects, while C does not support these features. 3) The C code sample demonstrates the basic structure and syntax of a C program, including header files, functions, and output statements.

Uploaded by

shanraj330
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

C Coarse

The document provides an overview of the C programming language, including: 1) C was developed by Dennis Ritchie and used to create the UNIX operating system. It is faster than languages like Python and Java. 2) C++ is an extension of C that supports classes and objects, while C does not support these features. 3) The C code sample demonstrates the basic structure and syntax of a C program, including header files, functions, and output statements.

Uploaded by

shanraj330
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

starting and basic code of C lang

1 #include <stdio.h>
2
3 int main() {
4 printf("Hello World!");
5 return 0;
6}

Intro of C- lang

->C lang is developed by Dennis Ritchie.


->C lang is used to develop the OS known as "UNIX"

Benefits of learning 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

Difference between C & C++

-> C++ is nothing but an extension of C lang


-> these both langs have the almost same syntax
-> C++ supports classes & objects but C lang cant

Installing C lang in IDE

-> 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

-> we include function printf() to out the output


-> and to insert another line, we should insert the printf function down to the 1st
printf function
printf("HELLO WORLD")
printf("MY NAME IS SUSHANTH")
-> to insert the new lines, we should include the /n function in the output passage
written in the printf function
example:
printf("HELLO WORLD"/nMY NAME IS SUSHANTH")
result:
HELLO WORLD
MY NAME IS SUSHANTH

-> 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")

/" function helps to output or specify the word in the sentence


example:
printf("MY NAME IS SUSHANTH")
result:
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;

-> we can write the statement by also expanding


example:
int Num1;
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 );

-> double- %lf


example:
double part = 1/4
printF( %lf, part );

-> 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)

-> if all variables are the same,


example:
int x, y, z;
int x = y = z = 30,
printf("%d", x + y + z)
NOTE:
-> The basic rules of naming variables:

i]Names can contain letters, digits, and underscores


ii]Names must begin with a letter or an underscore (_)
iii]Names are case sensitive (myVar and myvar are different variables)
iv]Names cannot contain whitespaces or special characters like! #, %, etc.
v]Reserved words (such as int) cannot be used as names

C data types:

-> data types are nothing but variables


-> data types are types that help to represent the type of data written in the code
-> different data types take a different amount of space.

-> int takes 2 to 4 bytes


-> float takes 4 bytes
-> char takes 1 byte
-> double takes 8 bytes

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

-> however, expansion of code doesn't work


example:
const int Num1;
Num1 = 10;

-> 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 ELSE (short)

-> 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

You might also like