You are on page 1of 21

Hearty Welcome to

The Bridge Course


on

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Introduction
to

C
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
Objectives:

Attendees of this course will be in a position to:

• understand the background of C


• understand the structure of C Programming
• create identifiers for objects in a program
• list, describe and use the basic data types
• understand input and output concepts
• use simple input and output statements
• write simple programs

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
C
• Developed in 1970s
• Developed by Dennis M Ritchie at Bell Laboratories
• Structured Programming Language
• High level language
• General purpose language
• The code runs nearly as fast as code written in assembly language.
• Machine-independent
• Instructions consists of :
• Algebraic expressions
• English keywords – if, else, for, do, while
• Acts as a bridge between Machine Language and High level language
• One can do system as well as application programming.

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Brian Wilson Kernighan Ken Thomson Dennis M Ritchie

Brian Wilson Kernighan (Canadian) worked at Bell Laboratories and contributed to the
development of Unix alongside Unix creators Ken Thompson (American) and Dennis Ritchie
(American). Kernighan's name became widely known through co-authorship of the first book on
the C programming language with Dennis Ritchie

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Is C language is still useful?
C program is:
• Efficient, high performance, high quality
• Flexibility and power
• Many high-level, middle level and low-level operations
• Can be used to develop operating systems to menu driven programs
• Low level - directly interfaced with the processor
• Stability and small size code
• Provide functionality through rich set of function libraries
• Gateway for other professional languages like C C++ Java
The uses of C:
• Operating Systems
• Language Compilers
• Assemblers, Text Editors, Print spoolers
• Network Drivers, Device drivers
• Modern Programs, Embedded systems, System level routines
• Data Bases, Language Interpreters
• Data compression, Graphics and Computational geometry, Utility Programs
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
Some of the interview questions
1. Why is C called a mid-level programming 3. What is a token?
language?
• Smallest unit in the program (statement).
C has both the characteristics of assembly-level • The individual elements of a program are called
i.e. low-level and higher-level languages. Hence, Tokens.
C is usually called as middle-level language. C - • There are 6 types of tokens in C:
user can write programs to develop an operating • Identifiers
system and a menu-driven consumer billing • Keywords
system. • Constants
• Operators
2. What are the features of the C language? • Special Characters
• Strings
Few among them are:
1.It is Simple And Efficient.
2.C language is portable or Machine Independent.
3.C is a mid-level Programming Language.
4.It is a structured Programming Language.
5.It has a function-rich library.
6.Dynamic Memory Management.
7.C is super fast.
8.We can use pointers in C. DEPARTMENT OF MECHANICAL ENGINEERING
9.It is extensible. N.B.K.R.I.S.T. (AUTONOMOUS)
DEPARTMENT OF MECHANICAL ENGINEERING
Structure of C programming

// Simple C program to display "Hello World"

// Header file for input output functions


#include <stdio.h>

// main function -
// where the execution of program begins
int main()
{

// prints hello world


printf("Hello World");

return 0;
}

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
stdio.h
The header file stdio.h stands for Standard Input Output. It has the information related to input/output
functions.
The following table displays some of the functions in stdio.h in C language
S. No. Functions & Description
1 printf() - It is used to print the strings, integer, character etc., on the output screen.

2 scanf() -It reads the character, string, integer etc., from the keyboard.
3 getc() - It reads the character from the file.
4 putc() - It writes the character to the file.
5 fopen() - It opens the file and all file handling functions are defined in stdio.h header file.

6 fclose() - It closes the opened file.


7 remove() - It deletes the file.
8 fflush()
It flushes the file.

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Conio.h
• stands for console input & output header file.
• to develop interactive console applications.
• manages input and output to controlling cursor movements
• empowers to create dynamic, user-friendly console applications.

Conio.h header file also include

highvideo()
movetext()
gotoxy()
wherex()
& wherey().

These functions offer further flexibility and


control over console interactions in C
programming.

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
A computer program is
• a sequence or set of instructions in a programming language for a computer to execute.
• are one component of software, which also includes documentation and other intangible components.
• A computer program in its human-readable form is called source code.
• source code may be translated to machine instructions using the language's compiler.
• Assembly language programs are translated using an assembler.
• The resulting file is called an executable.
• Alternatively, source code may execute within the language's interpreter.
Syntax:
• refers to the rules that define the structure of a language.
• in computer programming means the rules that control the structure of the symbols, punctuation, and
words of a programming language.
• Without syntax, the meaning or semantics of a language is nearly impossible to understand.
• For example, a series of English words, such as — subject a need and does sentence a verb — has little
meaning without syntax.
• Applying basic syntax results in the sentence — Does a sentence need a subject and verb?
• This tells the computer how to read the code.
• refers to a concept in writing code dealing with a very specific set of words and a very specific order to
those words when one give the computer instructions.

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Operating System (OS)

It is a system software that manages computer h


ardware and software resources and provides
common services for computer programs.

Application software

It is a kind of software that performs specific


functions for the end user by interacting directly
with it.
The sole purpose of application software is to aid
the user in doing specified tasks.

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
Character set of C

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
Identifiers

• These are the fundamental building blocks of a program


• These are used to identify things
• Names given to the variables, functions, constant and user defined data
• User defined names consists of a sequence of letters and digits.

Guidelines for defining Identifier

• It is a name, of size 1 to 31 characters


• With a combination of alphabets, digits and special symbols.
• Starts with either alphabet or underscore.
• Should not have blanks or special symbols in between other than an underscore.
• Keywords are not to be used as an identifiers.
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
• Identifier refers to the name given to entities such as variables, functions,
structures etc..
• Identifiers must be unique.
• They are created to give a unique name to an entity to identify it during the
execution of the program.
• For example: money, account_balance, name, roll_no, _address1#, _address2#
Alphabets & Digits Special Characters in C White space Characters
Uppercase: A,B, ….. , < > . _ Blank space,
Lowercase: a,b,c, …. newline,
1,2,3, ……… ( ) ; $ :
horizontal tab,
% [ ] # ? carriage return and form feed.

' & { } "

^ ! * / |

- \ ~ +

DEPARTMENT OF MECHANICAL ENGINEERING


N.B.K.R.I.S.T. (AUTONOMOUS)
DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)
C Keywords
• Keywords are predefined, reserved words used in programming that have special
meanings to the compiler.
• These are part of the syntax and they cannot be used as an identifier.
• C is a case sensitive language, all keywords must be written in lowercase. Here is a
list of all keywords allowed in ANSI C.

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 goto sizeof volatile

const float short unsigned


DEPARTMENT OF MECHANICAL ENGINEERING
N.B.K.R.I.S.T. (AUTONOMOUS)

You might also like