Introduction to C Programming: Basics, Structure, Data Types, and Program Development, Study notes of C programming

This document provides an introduction to the C Programming Language, covering its history, features, characteristics, and applications. It explains the structure of a C program, program development life cycle (compiler, linker, and loader), coding rules, comments, header files, preprocessor directives, and library functions. The document also discusses C tokens, keywords, identifiers, variables, escape sequences, and data types. Additionally, it highlights the uses of C in operating systems, embedded systems, and software development, making it a foundational guide for beginners learning C programming concepts.

Typology: Study notes

2025/2026

Available from 06/15/2026

neha-jindal-1
neha-jindal-1 🇮🇳

5 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MCA First Year- KCA 102
Unit-1.3 Programming in C
Introduction
C Programing language is a general-purpose middle level (Partially low and Partially High level)
Language. C is a programming language. C is one of the oldest and finest programming languages. was
developed by Dennis Ritchie in 1972. It is relatively small language as its small, unambitious feature set
is a real advantage: there's less to learn;
C programming language is a general-purpose, procedural, structured and imperative computer
programming language
It is developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX
operating system.
C Language is the most widely used computer language. It keeps fluctuating at number one scale of
popularity along with Java programming language, which is also equally popular and most widely
used among modern software programmers.
It is partially low and partially high-level language means it can handle low-level and high-level
activities
C was invented to write an operating system called UNIX. The UNIX OS was totally written in C.
It is a successor of B language which was type less
The language was formalized in 1988 by the American National Standard Institute (ANSI).
Most of the state-of-the-art software have been implemented using C. It can be compiled on a variety
of computer platforms
History of C Language
In the early days, in general every language was designed for some specific purpose. like FORTRAN
(Formula Translator) was used for scientific and mathematical applications, COBOL (Common Business
Oriented Language) was used for business applications. Thus need of a language was recognized which
could withstand most of the purposes. "Necessity is the mother of invention". This was the first step
towards C was put forward by Dennis Ritchie.
The C programming language was developed in 1972, at Bell laboratories by Dennis Ritchie. Initially it
was designed for programming in the operating system called UNIX. After the advent of C, the whole
UNIX operating system rewritten using C language only. Now almost tlvc entire UNIX operating system
and the tools supplied with it including the C compiler itself are written in C. The C language is derived
from the B language, which was written by Ken Thompson at AT&T Bell laboratories.
The B language was adopted from a language called BCPL (Basic Combined Programming
Language), which was developed by Martin Richards at Cambridge University
Characteristics of C
It is a middle level language. It has the simplicity of a high-level language as well as the power
of low level language. This aspect of C makes it suitable~ for writing both application' programs
and system programs.
It is an excellent, efficient and general-purpose structured, procedural, modular imperative
programming language.
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Introduction to C Programming: Basics, Structure, Data Types, and Program Development and more Study notes C programming in PDF only on Docsity!

MCA First Year- KCA 102 Unit- 1 .3 Programming in C Introduction C Programing language is a general-purpose middle level (Partially low and Partially High level) Language. C is a programming language. C is one of the oldest and finest programming languages. was developed by Dennis Ritchie in 1972. It is relatively small language as its small, unambitious feature set is a real advantage: there's less to learn;  C programming language is a general-purpose, procedural, structured and imperative computer programming language  It is developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.  C Language is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.  It is partially low and partially high-level language means it can handle low-level and high-level activities  C was invented to write an operating system called UNIX. The UNIX OS was totally written in C. It is a successor of B language which was type less  The language was formalized in 1988 by the American National Standard Institute (ANSI).  Most of the state-of-the-art software have been implemented using C. It can be compiled on a variety of computer platforms History of C Language In the early days, in general every language was designed for some specific purpose. like FORTRAN (Formula Translator) was used for scientific and mathematical applications, COBOL (Common Business Oriented Language) was used for business applications. Thus need of a language was recognized which could withstand most of the purposes. "Necessity is the mother of invention". This was the first step towards C was put forward by Dennis Ritchie. The C programming language was developed in 1972, at Bell laboratories by Dennis Ritchie. Initially it was designed for programming in the operating system called UNIX. After the advent of C, the whole UNIX operating system rewritten using C language only. Now almost tlvc entire UNIX operating system and the tools supplied with it including the C compiler itself are written in C. The C language is derived from the B language, which was written by Ken Thompson at AT&T Bell laboratories. The B language was adopted from a language called BCPL (Basic Combined Programming Language ), which was developed by Martin Richards at Cambridge University Characteristics of C  It is a middle level language. It has the simplicity of a high-level language as well as the power of low level language. This aspect of C makes it suitable~ for writing both application' programs and system programs.  It is an excellent, efficient and general-purpose structured, procedural, modular imperative programming language.

 It used for mathematical, scientific, business and system software applications. C is small language, consisting of only 32 English words known as keywords (if, else, for, break etc.:  The power of C augmented by the library functions provided with it. Moreover, the language is extendible since it allows the users to add their own library functions to the library. C contains control constructs needed to write a structured program hence it is also known as a structured programming language.  It includes structures for selection (if.. .else, switch), repetition (while, fo do...while) and for loop exit\ (break)...  The programs written in C are portable i.e. programs written for one type of computer or operating system can be run\on another type of computer or operating system  C also used to develop games, an area where latency is very important i.e. computer has to react quickly on user input. Uses of C: C is a language that is used to program a wide variety of systems. Some of the uses of C are as follows:  Major parts of Windows, Linux, and other operating systems are written in C.  C is used to write driver programs for devices like Tablets, Printers, etc.  C language is used to program embedded systems where programs need to run faster in limited memory. General Rules for programming in C

Structure of a C program  In C, comments begin with the sequence /* and are terminated by /.  Anything that is between the beginning and ending comments symbols is ignored by the compiler. Example: / sample program */  n C, blank lines are permitted and have no effect on the program.  A non-trivial C application typically has following general portions on it: The structure of a C program looks as follows: All c programs have to follow a basic structure. A c program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;) There are some basic rules which are applicable to all the c programs:

  1. Every program's execution starts from the main function.
  2. All the statements are terminated with a semi-colon.
  3. Instructions are case sensitive.
  4. Instructions are executed in the same order in which they are written. Comments Comments are used to clarify something about the program in plain language. It is a way for us to add notes to our program. There are two types of comments in c:
  5. Single line comment: //This is a comment.
  6. Multi line comment : /This is multi line comment/ Comments in a C program are not executed and ignored. Compilation and execution A compiler is a computer program which converts a c program into machine language so that it can be easily understood by the computer A program is written in plain text. This plain text is a combination of instructions in a particular sequence. The compiler performs some basic checks and finally convert the program into an executable. Library functions

Elements of a typical C Program Preprocessor: C libraries : Most of its intelligence is compartmentalized in libraries Almost all c programs use the “stdio” or standard input/output library. Many also use the “math” library. To use a library, include the header file (I.e., “stdio.h”) at the top of the file. For most special purpose libraries (I.e., math) you need to include the library on the link line. Every C program line begins with # provides an instruction to the C preprocessor. It is executed before the actual compilation is done. Two most common directives: ◦ #include ◦ #define In our example (#include) identifies the header file for standard input and output needed by the printf().  # includes: An include directive tells the preprocessor to include the contents of the specified file at the point in the program. Path names must either be enclosed by double quotes or angle brackets.  Header Files (.h): Header files contains declaration information for standard library functions or constants that are referred in programs. They are used to keep source-file size to a minimum and to reduce the amount of redundant information that must be coded. A header file can be included in following ways: 1: # include : the <> tells the preprocessor to search for the included file in a special known \include directory or directories. 2: # include “mylib.h” the double quotes (“ ”) indicate that the current directory should be checked for the header file first. If it is not found, the special directory (or directories) should be checked. 3 # include “mine\include\mylib.h” It is similar to 2, but the named relative directory \mine\include is checked for the header file mylib.h. Relative paths can also be proceeded by the .\ or ..\ notation; absolute paths always begin with a . # defines: ANSI C allows you to declare constants. The # define directive is used to tell the preprocessor to perform a search-and-replace operation. Example:

define Pi 3.

define Tax-rate 0.

In the example above, the preprocessor will search through the source file and replace every instance of the token Pi with 3.14159 After performing the search and replace operation, the preprocessor removes the # define line.  User defined function prototypes: Declares the user-written functions actually defined later in the source file.  A function prototype is a statement (rather than an entire function declaration) that is placed a head of a calling function in the source code to define the function's label before it is used. A function prototype is simply a reproduction of a function header (the first line of a function declaration) that is terminated with a semi-colon.  Function main () in C :  Compiler identify the start of the program. Every C program has a main ( ). 'main' is a C keyword. We must not use it for any other variable. There are following four common ways of main declaration

int

main(void)

return 0;

void

main(void)

main(void)

main( )

Keywords These are reserved words, whose meaning is already known to the compiler. There are 32 keywords available in c: auto double int struct break (^) long else switch case return enum typedef char register extern union const short float unsigned continue signed for void default sizeof goto volatile do (^) static if while Identifiers A 'C' program consist of two types of elements, user defined and system defined. Identifiers is nothing but a name given to these elements. An identifier is a word used by a programmer to name a variable, function, or label. identifiers consist of letters and digits, in any order, except that the first character or label. Identifiers consist of letters and digits if any order, except that the first character must be letter. Both Upper and lowercase letters can be used

Rules Example

Can contain a mix of characters and numbers. However it cannot start with a number H2o First character must be a letter or underscore Number1; _area Can be of mixed cases including underscore character XsquAre my_num Cannot contain any arithmetic operators R*S+T … or any other punctuation marks… #@x%!! Cannot be a C keyword/reserved word struct; printf; Cannot contain a space My height … identifiers are case sensitive Tax != tax  Variables  "Variables" are simply storage locations to hold data. For every variable, some memory is allocated. The  size of this memory depends on the type of the variable. For example, 2 bytes are allocated for integer  type, 4 bytes are allocated for float type, etc.  thus a variable is like a container that stores a ‘value’. Like we have containers at home for storing rice, dal, sugar, etc. Similar to that variable in c stores value of a constant. Example: a = 3; //a is assigned “3” b =4.7; //b is assigned “4.7” c=’A’; //c is assigned “A” Rules for naming variables in c:

  1. The first character must be an alphabet or underscore (_).
  1. No commas, blanks allow.
  2. No special symbol other than underscore is allowed
  3. Variable names are case sensitive Escape Sequences Sometimes, it is necessary to use characters which cannot be typed or has special meaning in C programming. For example: newline(enter), tab, question mark etc. In order to use these characters, escape sequence is used. For example: \n is used for newline. The backslash ( \ ) causes "escape" from the normal way the characters are interpreted by the compiler. Escape Sequences Character \b Backspace \f Form feed \n Newline \r Return \t Horizontal tab \v Vertical tab \ Backslash ' Single quotation mark " Double quotation mark ? Question mark \ 0 Null character C language has a lot of valuable library functions which is used to carry out a certain task, for instance, printf function is used to print values on the screen. printf(“This is %d”,i); // %d for integers // %f for real values // %c for characters Types of variables Integer variables - int a=3; Real variables - int a=7.7 (wrong as 7.7 is real) ; float a=7.7; Character variables - char a=’B’; C Data Types In the C programming language, data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The types in C can be classified as follows: S.N. Types and Description 1 Basic Types: They are arithmetic types and consists of the two types: (a) integer types and (b) floatingpoint types