This document discusses key concepts in C programming including variables, data types, constants, keywords, comments, and rules for writing C programs. It defines variables as containers for storing data in memory locations. It describes predefined data types like char, int, float, and double as well as derived and user-defined data types. It also covers identifiers, declarations, initialization, keywords, constants, comments, and general rules for writing C programs.
Variables • Variable issimply name given to memory location which acts as placeholder or container for storing data. It may help to think of variables as a container for a value.
3.
Data type • Wecan store variables in our computer memory. Since each type of data takes different amount of memory, like integer takes 2 bytes, decimal numbers take 4 byte, and SINGLE character takes 1 byte. So we have to tell computer about the type of data we are going to store in our variable
4.
• Predefined/inbuilt : Thesedatatypes are inbuilt. eg : char, int, float, double • Drived Datatype These datatypes are inherited from predefined datatype. eg : arrays, pointer. • Userdefined datatype : These are created by user for his/her own purpose • eg : typedef, enum, structure, union
Character set • Characterset: every character is assigned unique number called character set. C/C++ follows ASCII character set. • ASCII: American standard code for information interchange • Here lowercase, uppercase characters (English), special symbols, digits have been assigned unique integer number. • Total 256 characters are there. • Range is: -128 to 127 • Here limitation is only English is used.
9.
Identifiers • Identifier issimply a name given to your variable, class, union, structure, function, etc. • Rules for creating valid identifiers: • 1. An identifier can be any combination of alphabets, digits, underscore. • 2. Neither spaces nor special symbol other then underscore can be used. • 3. It won‘t begin with a digit
11.
Declaration and initializationof variable • How to declare variable? • Declaration of variable means specify data type of variable and name assigned (identifier). • A variable declaration provides assurance to the compiler that there is one variable existing with the given type and name so that compiler proceed for further compilation without needing complete detail about the variable.
12.
• syntax : datatypevarible_name; eg : int a; float b; char c; double first; int i, j, k;
Declaration and initializationin single step int a = 10; float b = 30.05; char c = 'a'; (Value to characters always assigned in single quotes)
15.
Keywords • Are simplythe reserved words whose meaning has been explained in library of C language. • There are 32 keywords in c language. • We can’t use keywords as identifiers or variables because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer
int float; char if; Intvoid; Above will give error as we are using keywords as identifier or variable name
18.
Constants • Is anidentity which does not change its value. Once the value is initialized, that can’t be changed. • Constants are just like variables only condition is that their value doesn’t change. • We will use const keyword for declaring constants
19.
Comments • Comments arethat part of program, which are ignored by compiler. These are used for better readability of user. Compiler doesn‘t compile the text written inside comments. • The comment describes the purpose of the code in the file, and might include some license or copyright information. • It is not compulsory to have comments in our program, but its good practice and what most C programmers will expect to find.
20.
Single Line Comment //is used to make single line comment. All the text in a line after // will become part of comment and will be ignored by compiler. • E.g. int a; // this is ignored
21.
Multiline Comment This startsfrom /* and ends at */. All the text in between these will be part of comment. E.g. /* This Is Multiline Comment */
22.
Rules for writingc program • Every instruction in c program is written as separate statement because C program is collection of statements • There is no particular hard and fast rule for placing the statements in our program. We can place it anywhere in our program, that why C is known as free form language. • Every statement will end with ; (semi-colon). So it is also known as statement terminator. • Proper comments and indentation should be given in c program for better readability • C is case sensitive language. It differs in lower and upper case characters. • We can‘t declare variable with same name multiple times in single block.