Professional Documents
Culture Documents
D off MCA
Programming
Concepts & C
Subject Code: MCA 14 Language.
http://www.pes.edu
PESIT – Dept. of MCA • Computer Concepts and
Programming Concepts
• Introduction of C
• Fundamental Of C
• Preprocessor
Overview of flow of • Decision Control
Structures
Subject • Loop Control Structures
• Functions Storage
g
Classes
• Arrays and Pointers
• Strings
• Structure and Unions
• Bitwise Operators
• File Handling
g
http://www.pes.edu
PESIT – Dept.
Dept of MCA
• Introduction to Computers.
• C Programming
g g Language.
g g
• Data Structures and Algo.
• OS Concepts.
CORE COMPETENCE • UNIX OS.
• Object Oriented Programming
• C++ Programming Language
From Here?
http://www.pes.edu
PESIT – Dept.
Dept of MCA
Problem
gy
Solution Methodology
( Algorithm)
Programming Language
( C, C++, etc.,)
Program + Data
Flowchart to go
through problems Solve
Example Result
http://www.pes.edu
PESIT – Dept.
Dept of MCA ALGOL 60
(International Committee -1960)
CPL
(Cambridge & Univ. Of London-1963)
BCPL
DEVELOPMENT OF C (Martin Richards-cambridge-1967)
B
(Ken Thompson,Bell Labs.1970)
C
(Dennis Ritchie,bell Labs.1972)
http://www.pes.edu
PESIT – Dept.
Dept of MCA • H
H.L.L:
L L: Better program
efficiency. Ex: Fortran etc.,
• L.L.L.: Better machine
efficiency. Ex: Assembly etc.,
http://www.pes.edu
PESIT – Dept. of MCA EDITOR
C SOURCE CODE
C PREPROCESSOR
STAGES IN C COMPILER
LINKER
EXECUTABLE CODE
LOADER
http://www.pes.edu
PESIT – Dept.
Dept of MCA
http://www.pes.edu
PESIT – Dept.
Dept of MCA
C Character set:
FUNDAMENTALS OF C
• Character set A-Z
• Character set a-z
• Digits 0-9
• Special
p Characters like *,, +,, -
, ( , ) , < , > etc.,
http://www.pes.edu
PESIT – Dept.
Dept of MCA
http://www.pes.edu
PESIT – Dept.
Dept of MCA Integer Constant:
• Must have at least one
digit.
• Should not contain decimal
point.
• Could be either +ve or _ve.
TYPES OF C
CONSTANTS Real Constants: Two forms
1. Exponential form:
mantissa & exponent , they
should be separated by
letter e.
2. Fractional form
Character constant:
single character/digit. Ex.
‘A’ max length is one.
http://www.pes.edu
PESIT – Dept.
Dept of MCA
http://www.pes.edu
PESIT – Dept.
Dept of MCA
scanf() :
I/O
/ OPERATIONS Allows you to input data from
standard
d d input
i device.
d i
IN C Ex: scanf(“%d”, &var);
printf():
Allows you to output data on
standard output device.
Ex: printf(“%d”, var);
http://www.pes.edu
PESIT – Dept.
Dept of MCA How does C program look like?
/* Sample Program */
main(){
i (){
printf(“\n Welcome to C”);
}
Operations C PASCAL
Addition + +
Subtraction - -
Multiplication * *
Division / DIV
OPERATORS AND ITS Remainder % MOD
HIERARCHY
Ex: on=ink
on=ink*act/2+3/2*act+2+t;
act/2+3/2 act+2+t;
ink=3, act=2, t=2.2;
O/P: on=9.2
Ex: s=qui*add/4-6/2+2/3*6/go;
qui=2, add=4, go=3;
O/p: s=-1
s= 1
http://www.pes.edu
PESIT – Dept. of MCA
Ex: a=7//2*(3.14+2)*3/5
http://www.pes.edu
PESIT – Dept.
Dept of MCA OPERATIONS C PASCAL
equal to == =
http://www.pes.edu
PESIT – Dept.
Dept of MCA OPERATIONS C PASCAL
Negation ! NOT
L i l AND
Logical && AND
Logical OR || OR
LOGICAL
S
Synopsis
i off LLogical
i l AND & OR.
OR
OPERATORS
T– True F– False
T && T = T T || T = T
T && F = F T || F = T
F && T = F F || T = T
F && F = F F || F = F
http://www.pes.edu
PESIT – Dept.
Dept of MCA Increment operators:
a = a + 1 is same as a+=1
OR
a++ (post
( t iincrement)
t) or
INCREMENT ++a (pre increment)
OPERATOR Similarly decrement operator.
C be
Can b used d for
f prefix
fi or suffix.
ffi
AND
FORMAT Format Specification:
%d integer
SPECIFICATION %f real, float
%c character
%s string
%o octal
%x hexadecimal
%u unsigned integer
http://www.pes.edu
PESIT – Dept.
Dept of MCA
Problem
P bl 1:
1
main(){
int x;
x=-3+4*5-6;
? printf(“\n x=%d”,
xx=3+4%5-6;
3+4%5 6;
printf(“\n x=%d”,
x);
x);
VALIDITY OF CODE x=-3*4%-6/5;
printf(“\n
i tf(“\ x=%d”,
%d” x);
)
x=(7+6)%5/2;
printf(“\n x=%d”, x);
}
Sol: x=11,
x 11, x
x=1,
1, x
x=0,
0, x
x=1
1
http://www.pes.edu
PESIT – Dept. of MCA
Problem 2:
main(){
printf(“\n %d %o
%x”,72,72,72);
%x 72 72 72);
? }
http://www.pes.edu
PESIT – Dept. of MCA
Problem 4:
main(){
? printf(“\n
printf(“\n
printf(“\n
%d”,
%d”,
%d”,
4/3);
4/-3);
-4/3);
VALIDITY OF CODE printf(“\n %d”, -4/-3);
}
http://www.pes.edu
PESIT – Dept.
Dept of MCA
P bl
Problem 5:
5
main(){
printf(“\n %d”, 4%3);
? printf(“\n
printf(“\n
printf( \n
printf(“\n
%d”,
%d
%d”,,
%d”,
4%-3);
-4%3);
4%3);
-4%-3);
VALIDITY OF CODE }
Sol: 1, 1, -1, -1
http://www.pes.edu
PESIT – Dept.
Dept of MCA
Problem
P bl 6:
6
main(){
printf(“ Hello, world
“ );
? }
Sol: Compilation error
Unterminated String / Char
VALIDITY OF CODE Const.
Problem 7:
main(){
printf(“ Hello world” )
;
}
Sol: Hello world
http://www.pes.edu
PESIT – Dept.
Dept of MCA
Problem
P bl 8:
8
main(){
int i = 5;
printf (“%d“, i = i == 6 );
? }
Sol: 0
http://www.pes.edu
Problem
P bl 10 :
PESIT – Dept.
Dept of MCA
main(){
int a,b=2,c;
? a=2*(b++);
c=2*(++b);
VALIDITY OF CODE printf (“ %d %d
%d“, a,b,c);
}
Sol: 4 4 8
http://www.pes.edu
P bl
Problem 11 :
PESIT – Dept.
Dept of MCA
main(){
i (){
?
int k=35;
printf(“\n %d %d %d “,
k==35,k=50,k>40);
}
VALIDITY OF CODE
Sol: 0 50 0
http://www.pes.edu
PESIT – Dept.
Dept of MCA 1) How should I decide
which integer type to
use
2) Under my compiler this
code prints 49
int i=7;
printf(“%d”,i++
p ( , * i++);
);
HOW ABOUT
Regardless of the order
of evaluation, should’nt
it print 56.
ASSIGNMENTS 3) Is it safe to assume
that the right hand side
of the && and ||
operators won
won’tt be
evaluated if the left
hand side determines
the outcome.
http://www.pes.edu
PESIT – Dept.
Dept of MCA
4) P
Peoplel keep
k saying
i
that the behavior of i =
i++ is undefined, but I
just tried it on an ANSI
conforming compiler
and got the results I
HOW ABOUT expected.
5) If I’m not using the
value of the
ASSIGNMENTS expression, should I
use i++ or ++I to
( cont ) increment a variable.
6) Y does’nt
does nt this code
work :
int a=1000,b=1000;
long int c
c=a*b;
a b;
http://www.pes.edu
PESIT – Dept.
Dept of MCA
7) HHow do
d I round d off
ff th
the
numbers.
8) Y does’nt C have an
exponentiation
ti ti
operator.
9) What is top down
HOW ABOUT d i
design methodology.
th d l
What R its advantages.
10) How does operation of
ASSIGNMENTS an interpreter
i t t differ
diff
(cont) from compiler.
http://www.pes.edu
PESIT – Dept.
Dept of MCA
“ It is a program that
preprocesses the source
code, before it passes
through compiler. Operates
under what is called as
P
Preprocessor C
Command d lines
li
PREPROCESSOR or Directives ”
http://www.pes.edu
PESIT – Dept. of MCA
Grouped under three categories:
• File Inclusion Directives :
Achieved by # include.
Syntax: #include<filename>
Ex: #include<stdio.h>
• Macro Substitution :
PREPROCESSOR Identifier in a program is
replaced by some predefined
strings composed of tokens.
Ex: #define MAX 100
• Compiler Control :
Selectivelyy removingg the code
sections or choosing form two
sections. Such process called as
Conditional Compilation.
http://www.pes.edu
PESIT – Dept. of MCA Ex: - - -
main(){
---
#ifdef IBM-PC {
---
--- /* code for IBM-
PC *//
PREPROCESSOR }
#else{
---
--- /* code for HP */
}
#endif
}
To run prg on IBM-PC we include:
#define IBM
IBM-PC.
PC.
http://www.pes.edu
P bl
Problem 1:
PESIT – Dept. of MCA
?
#define PRODUCT(x) (x*x)
(x x)
main(){
int i=3,j;
VALIDITY OF CODE j PRODUCT(i+1);
j=PRODUCT(i+1);
printf(“\n %d “,j);
}
Sol : 7
http://www.pes.edu
P bl
Problem 2:
PESIT – Dept. of MCA
?
#define PRODUCT(x) (x*x)(x x)
main(){
int i=3,j,k;
VALIDITY OF CODE j PRODUCT(i++);
j=PRODUCT(i++);
k=PRODUCT(++i);
printf(“\n %d %d“,j,k);
}
Sol : 9 49
http://www.pes.edu
PESIT – Dept. of MCA
What do U mean by a platform.
How do U classify computer
according to logic use.
How do U classify computer
according to size.
Diff. b/w :
Q
Questions
ti RAM & ROM
PROM & EPROM
Different generations
Batch & Transaction processing
Hardware
Software & its classification
http://www.pes.edu
PESIT – Dept. of MCA
Internet
What it is
Who made it
WWW / Web server etc
Internet & Intranet
Q
Questions
ti ( contt )
http://www.pes.edu
PESIT – Dept. of MCA
Explain the organization of the
digital computer.
What is the need for secondary
storage devices. Write note on
hard disk.
Explain the working principle of
different
d e e t types oof p
printers.
te s
A i
Assignments
t :
What is an O.S. Explain its
various functions.
Diff b/w :
Diff.
Assemble & HLL
What is Computer N/w. Explain
briefly different types of nw
nw.
http://www.pes.edu
PESIT – Dept. of MCA
Differentiate between primary
memory and secondary
memory.
Explain input and output
devices along with examples.
Define :
A i
Assignments
t ( contt ) : OS
O.S
Compiler
Interpreter
Editor
Edit
Explain features of UNIX O.S
Note on Internet & E-mail.
http://www.pes.edu
PESIT – Dept. of MCA Logic is very important in
programming.
Fl
Flowchart
h t Example
E l : 1) Put
P the
h clothes
l h ini the
h
washtub.
2) Pour water.
3) Pour detergent powder.
powder
4) Switch on the washing
machine.
5) Set the timer and wait
f a few
for f minutes.
i t
6) Drain the water out.
7) End.
http://www.pes.edu
PESIT – Dept. of MCA This procedure gets the
workk done.
d
http://www.pes.edu
PESIT – Dept. of MCA
In this case,
case your clothes
may tear off, since you
have switched on the
washing machine before
pouring water into it.
Fl
Flowchart
h t Example
E l If you apply the above
analogy to programming,
( cont ) : you should carefully think
about the order in which
the instructions are
carried out by your
computer. This is
precisely what logic is all
about.
http://www.pes.edu