0% found this document useful (0 votes)
19 views

C Language

The document provides an overview of variables, data types, input/output, and the basic structure of C programs. It discusses rules for writing variables, built-in data types and their sizes, constants, keywords, comments, and the typical parts of a C program like main and return statements.

Uploaded by

hsgdyhsuh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

C Language

The document provides an overview of variables, data types, input/output, and the basic structure of C programs. It discusses rules for writing variables, built-in data types and their sizes, constants, keywords, comments, and the typical parts of a C program like main and return statements.

Uploaded by

hsgdyhsuh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

C language Notes.

Chapter 1- Variables and Data Types + Input/ Output.

Variable – It is the name of a memory location that stores some


data. Its value can be changed by the user.

Rules to write variables: -


a) Variables are case-sensitive.
b) 1st Character should be an alphabet or ‘_’.
c) No comma/ blank spaces.
d) No other symbols other than ‘_’.

Tip: The name of the variable should be meaningful.

Sample Code: -

# include <stdio.h>

int main () {
printf(“Hello World”);
return 0;
}
Data Types

DATA TYPE SIZE IN BYTES


CHAR OR SIGNED CHAR 1
UNSIGNED CHAR 1
INT OR SIGNED INT 2
UNSIGNED INT 2
SIGNED SHORT INT OR SHORT 2
INT
UNSIGNED SHORT INT 2
LONG INT OR SIGNED LONG 4
INT
UNSIGNED LONG INT 4
FLOAT 4
DOUBLE 8
LONG DOUBLE 10

Int – It is used to store integer values in C.


Float – It is used to store decimal values in C.
Char - It is used to store characters in C.

Constants - Their value doesn’t change like variables. It means


that their value is fixed.
Constants have three types: -
1) Integer Constants.
Example= 1,2,3,0, -1, -2.

2) Real Constants.
Example= 1.0,2.0,3.0,3.14, -2.4.

3) Character constants.
Example= ‘a’, ‘b’, ‘c’, ‘A’, ‘#’, ‘&’, ‘_’.
Tip: - When we will write character constants we will always
have to write it in a single quote. Example: - ‘a’.

Keywords – They are the reserved words in C that have some


special meanings to the compiler. There are 32 keywords in
C. They are: -

auto double int struct


break else long switch
case enum register typedef
char extern return union
continue for signed void
do if static while
default sizeof goto volatile
const float short unsigned

Program Structure: -

#include <stdio.h>

int main () {

return 0;
}

1) <stdio.h> - it is the Preprocessor Directive


#include <stdio.h> & int main () {- We have to write this
#include <stdio.h> in the first line of our program and leave a
line for comment and then we will write this int main () { as
execution starts from this command.
2) Between the int main () { and return 0; we have to write
our code of C.
3) return 0; - This command is needed for the compiler to
execute the whole command that we have written in the
whole program.
4) The code that we will write should be of no mistakes or the
compiler will show errors.
5) The C compiler starts execution in a line-by-line method.
6) C is a case-sensitive code language that’s why we have to
write it in small letters and we can’t interchange it with
capital letters.
7) ; - This works as a full stop in the program of C

Comments – Lines that are not part of the program but are used to
give some extra instruction to the program.

Comments have two types: -


1) // – For single lines or multiple lines or we can say for both
2) /* */- For both types of lines multiple lines or single lines as it
is mostly used when we want to write multiple lines so it’s
recommended for multiple lines same with //

You might also like