100% found this document useful (1 vote)
231 views16 pages

C Programming Note (NEB)

This is the note of NEB grade 12 c programming note nepal #NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Educat

Uploaded by

Nirajan Acharya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
231 views16 pages

C Programming Note (NEB)

This is the note of NEB grade 12 c programming note nepal #NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Education_Board#NEB #National_Educat

Uploaded by

Nirajan Acharya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

PROGRAMMING IN C

(PART – I)

“See the Sea of C”

- BY PRAKASH KSHETRI

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


WHAT IS C PROGRAMMING?
 C is a general-purpose programming language that is extremely popular, simple
and flexible.
 It is machine-independent, structured programming language which is used
extensively in various applications.
 In 1972, a great computer scientist Dennis Ritchie created a new programming
language called 'C' at the Bell Laboratories.
 It was created from Algorithmic Language - 'ALGOL’, Basic Combined Programming
Language - 'BCPL' and ‘B’ (derived from BCPL) programming languages.
 'C' programming language contains all the features of these languages and many
more additional concepts that make it unique from other languages.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI
WHERE IS C USED? KEY APPLICATIONS
 'C' language is widely used in embedded systems.

 It is used for developing system applications.

 It is widely used for developing desktop applications.

 It is used for developing browsers and their extensions. Google's Chromium (free and open source
web browser) is built using 'C' programming language.
 It is used to develop databases. MySQL is the most popular database software which is built using
'C'.
 It is used in developing an operating system. Operating systems such as Apple's OS X, Microsoft's
Windows, and Symbian are developed using 'C' language. It is used for developing desktop as well
as mobile phone's operating system.
 It is used for compiler production.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


WHY LEARN C?
 As we studied earlier, 'C' is a base language for many programming languages. So, learning 'C' as
the main language will play an important role while studying other programming languages.
 'C' is a structured programming language in which program is divided into various modules. Each
module can be written separately and together it forms a single 'C' program. This structure makes
it easy for testing, maintaining and debugging processes.
 'C' contains 32 keywords, various data types and a set of powerful built-in functions that make
programming very efficient.
 Another feature of 'C' programming is that it can extend itself. A 'C' program contains various
functions which are part of a library. We can add our features and functions to the library.
 Various compilers are available in the market that can be used for executing programs written in
this language.
 It is a highly portable language which means programs written in 'C' language can run on other
machines. This feature is essential if we wish to use or execute the code on another computer.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


CHARACTER SET
 Every language such as English, Nepali have a collection of valid
characters.
 Likewise C has certain valid character sets.
 A character denotes any alphabet, digit or special symbols used to
represent information.
 Following are the valid character sets:

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


Types Characters

Alphabets Uppercase (i.e. A, B, ………………Y,Z) or lowercase (i.e. a, b, ………….y,z)


Digits 0,1,2, 3, 4, …………… 9
White Space Blank, new line, tab etc
Characters
Special Symbols
+ - * / = ( ) { } [ ] < > ‘
“ ! # % _ | ^ ~ \ ., ; : ?

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


COMMENTS (NON EXECUTABLE PART OF THE PROGRAM)
 Comments are remarks or arbitrary or random text written by a programmer into programming
codes for documentation purpose. C uses two types of comments:

 Single Line Comment which starts with two front slashes i.e. //

// This is an example of single line comment

 Multiple Line Comments which are placed between the character set i.e . /* and */

/* This is an example of multiple line comment ………………..


……………………….. */

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


TOKENS
 Tokens are the collection of different characters, symbols, operators
or punctuators.
 There are six types tokens as prescribed by C:
1. Keywords
2. Identifiers
3. Constants
4. String Constants
5. Operators
6. Punctuators

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


 Keywords:
 Keywords are predefined words that have strict meaning.
 Keywords can be defined as reserved words and they can not be used as names for variables or other
user defined program elements. If we do so, the compiler interprets it as a mistake and displays an error
message. There are 32 keywords in ANSI C (American National Standard Institute):

auto double if static


break else int struct
case enum (enumeration) long switch
char extern near typedef
const float register union
continue far return unsigned
default for short Void
do goto signed while

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


 Identifiers
 Identifiers are the programmer defined elements like the name of variables, functions, arrays,
structures, union etc.
 These are the tokens which are composed of sequence of letters, digits and underscore ( _ ).
 Identifiers are used to give unique names to different objects in the program.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


 Following are the rules for naming identifiers:
1. An identifier is any combination of alphabets, digits or underscore.
2. The first character in the identifier name must be an alphabet and not a digit but after that any
digit may follow.
3. No blanks (white spaces) are allowed within the identifier.
4. No special symbols other than underscore (as date_of_birth ) can be used in an identifier.
5. Maximum length of identifier is compiler dependent . Originally it was 8 characters. ANSI C
permits 31 characters.
6. Uppercase and lowercase letters are distinct. Such as radius and RADIUS refer to different
identifiers.
7. A keyword cannot be used as an identifier.
8. Identifier name should be unique. Same identifier name can not be used.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


Constants
 Constants also called literals, are the actual representation of fixed
values used in program which do not change during the program
execution.
 Different constants used in C are as follows:
 Integer Constant
 Decimal Constant
 Hexadecimal Constant
 Octal Constant
 Floating Point Constant
 Character Constant
LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI
Integer Constant
 The integer constants are the fixed numeric representation that
does not have fractional part. Integer constants may be positive or
negative numbers without fractional parts.
 Decimal Constants: Decimal constants are the integer numbers represented
with base 10 number system. No point or comma is allowed in Decimal
Integer Constants. Such as 300, 3466, -457 etc.
 Hexadecimal Constants: Hexadecimal constants are the integer numbers that
have base 16. Hexadecimal numbers are written using 0x (Zero X) before
actual digits. Such as 0x3AB2, 0X129F etc.
 Octal Constants: They are the integer numbers with base 8. Octal numbers
are written using 0 (Zero) before the octal digits. E.g. 034512, 0451 etc.

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


 Floating Point Constants
 The Fixed numeric representation that has fractional parts or exponential part is called floating point
constants or real constant.
 Some Examples of floating point constants are 3.147, 345.005, -45.67, 5.81e-23, 5.81e+23 etc.
 Where 5.81e-23 → 5.81*1/10^23 and 5.81e+23 → 5.81*10^23

 Character Constants:
 Single Character Constant:
 A character represented within single quotes denotes a character constant.
 Such as ‘a’, ‘z’, ‘4’, ‘@’, ‘$’ etc.
 String Constant:
 A sting constant is a character sequence enclosed within double quotes. If double quote ( “ ) or single quote ( ‘ ) are
to be part of the string then they should be preceded by back slash ( \ ).
 Such as: “Republic New Nepal”, “Ravi\’s wife” , “He said \”Health is wealth\””

LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI


LEARNING MANAGEMENT SYSTEM (LMS) BY PRAKASH KSHETRI

You might also like