The document is a comprehensive guide to programming in C, covering fundamentals such as data types, algorithms, control statements, functions, arrays, and pointers. It includes programming examples, explanations of operators, user input handling, and concepts of file handling in C. Additionally, it discusses different types of software applications and provides links to further resources.
Introduction to the workshop on Programming with C.
Aim: Gain practical coding experience with C programming.
Basics of software types: Application, System software, mentioning languages like Java and Python.
Definitions and roles of algorithms in problem-solving and data processing, with a specific example of Facebook login.
Overview of C as a procedural programming language, its origins, and the #include directive.
Details on escape characters, primary data types, and examples of variable definitions in C.
Explanation of format specifiers for different data types in C programming.
Types of operators: Arithmetic, Assignment, Relational, Logical, Bitwise, including examples and definitions.
Control structures for decision making and iteration: if statements, switch statements, and loops.
Overview of functions: declaration, calling, user-defined and standard library functions.Definition and examples of one-dimensional and multi-dimensional arrays in C.
Basics of pointers: definition, declaration, pointer arithmetic, and memory addressing.Introduction to file handling concepts in C, with a reference link to a code sample.
9801 200 111| [email protected]
Fundamental of software development
Application
Software
Games, MS Office,
Browser etc.
System Software
Operating System,
Tools & Utilities,
Compilers
Hardware
Disk, CPU, RAM
https://whatis.techtarget.com/definition/system-software
System Software
https://searchsoftwarequality.techtarget.com/definition/application
Application Software
C
5.
9801 200 111| [email protected]
Web Desktop Mobile
▪ Java
▪ .NET
▪ PHP
▪ Python
▪ Others
▪ Java
▪ .NET
▪ Python
▪ Others
▪ Android (java, Kotlin)
▪ iOS (Swift)
L
a
n
g
u
a
g
e
s
Types of
Application
9801 200 111| [email protected]
Algorithm
oHow to solve a class of problems.
oAlgorithms can perform calculation, data
processing, and automated reasoning tasks
9801 200 111| [email protected]
Introduction to C Programming
•C is a procedural programming language
•Developed by Dennis Ritchie
•Mainly developed as a system programming
language to write operating system
13.
9801 200 111| [email protected]
n is used to move the control onto the next line
t is used to give a horizontal tab i.e. continuous five spaces
#include <stdio.h>
void main()
{
printf(“welcome to C Programming”);
}
Header File
preprocessor
directive
return type
function
main
function
block
14.
9801 200 111| [email protected]
#include Directive
#include directive tells the preprocessor
to insert the contents of another file into
the source code at the point where the
#include directive is found
9801 200 111| [email protected]
Escape Characters
Symbol Description
n New Line
t Horizontal tab
v Vertical Tab
a Alarm
b Backspace
17.
9801 200 111| [email protected]
Data Types
Primary data types:
fundamental data types in C namely integer
Derived data types:
array, structure, union and pointer
9801 200 111| [email protected]
Integer
Type Size(bytes) Range
int or signed int 2 -32,768 to 32767
unsigned int 2 0 to 65535
short int or signed short int 1 -128 to 127
unsigned short int 1 0 to 255
long int or signed long int 4 -2,147,483,648 to
2,147,483,647
unsigned long int 4 0 to 4,294,967,295
20.
9801 200 111| [email protected]
Floating Point Type
Type Size(bytes) Range
Float 4 3.4E-38 to 3.4E+38
double 8 1.7E-308 to 1.7E+308
long double 10 3.4E-4932 to 1.1E+4932
9801 200 111| [email protected]
Format Specifier
Format specifier Description Supported data types
%c Character
char
unsigned char
%d Signed Integer
short
unsigned short
int
long
%e or %E
Scientific notation of float
values
float
double
%f Floating point float
24.
9801 200 111| [email protected]
Operators
An operator is a symbol which operates on a value or
a variable. For example: + is an operator to perform
addition.
9801 200 111| [email protected]
Input from user
void main()
{
int a,b;
printf(“Input any number”);
scanf(“%d%d”,&a,&b);
printf(“Number is %d %d”,a,b);
}
9801 200 111| [email protected]
Assignment Operator
Operator Example Same as
= a = b a = b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
32.
9801 200 111| [email protected]
Relational Operator
Operator Meaning of Operator Example
== Equal to 5 == 3 returns 0
> Greater than 5 > 3 returns 1
< Less than 5 < 3 returns 0
!= Not equal to 5 != 3 returns 1
>=
Greater than or equal
to
5 >= 3 returns 1
<= Less than or equal to 5 <= 3 return 0
33.
9801 200 111| [email protected]
Logical Operator
Operator Meaning of Operator Example
&&
Logial AND. True only if all
operands are true
If c = 5 and d = 2 then,
expression ((c == 5) && (d
> 5)) equals to 0.
||
Logical OR. True only if
either one operand is true
If c = 5 and d = 2 then,
expression ((c == 5) || (d >
5)) equals to 1.
!
Logical NOT. True only if
the operand is 0
If c = 5 then, expression !
(c == 5) equals to 0.
34.
9801 200 111| [email protected]
Bitwise
Operators Meaning of operators
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
<< Shift left
>> Shift right
9801 200 111| [email protected]
While
int n, i=1;
clrscr ();
printf ("enter the values of n");
scanf ("%d", &n);
printf ("natural numbers from 1 to %d ", n);
while (i<=n)
{
printf ("%d t", i);
i++;
}
46.
9801 200 111| [email protected]
for
int n,i;
clrscr();
printf("enter any number");
scanf("%d",&n);
for(i=1,i<=n,i++)
{
printf(“%d”,i);
}
9801 200 111| [email protected]
do…while
int n,i=1;
clrscr();
printf("enter any number");
scanf("%d",&n);
printf("natural numbers from 1 to %d",n);
do
{
printf("%dt",i);
i++;
}while(i<=n);
9801 200 111| [email protected]
Function
#include < stdio.h>
#include < conio.h>
void speakHello(); /* Function Declaration */
void main()
{
clrscr();
speakHello(); /* Function Calling */
getch();
}
void speakHello() /* Function Definition*/
{
printf("n WELCOME TO THE WORLD OF C LANGUAGE");
}
55.
9801 200 111| [email protected]
Function –return statement
#include < stdio.h>
int speakHello(int, int); /* Function Declaration */
void main()
{
clrscr();
printf(“%d”, speakHello(12,21)); /* Function Calling */
getch();
}
int speakHello(int x, int y) /* Function Definition*/
{
return (x+y);
}
9801 200 111| [email protected]
Find the sum of matrix
for(i=0;i<r;++i)
for(j=0;j<c;++j)
{
sum[i][j]=a[i][j]+b[i][j];
}
63.
9801 200 111| [email protected]
Pointers
pointer is a variable that contains an address
which is a location of another variable in
memory
64.
9801 200 111| [email protected]
Pointers
Datatype *pointer name
The asterisk (*) tells the variable ‘p’ is a pointer
variable.
‘p’ needs a memory location.
‘p’ points to a variable of type datatype.
int *p
9801 200 111| [email protected]
Pointer
int a=10;
int *b;
b=&a;
printf("value of a=%d n",a);
printf("value of a=%d n",*(&a));
printf("value of a=%d n",*b);
printf("address of a=%u n",&a);
printf("address of a=%u n",b);
printf("address of b=%u n",&b);
printf("value of b=address of a=%u n",b);
67.
9801 200 111| [email protected]
Pointer- Arithmetic
int main()
{
int m = 5, n = 10, o = 0;
int *p1;
int *p2;
int *p3;
p1 = &m; //printing the address of m
p2 = &n; //printing the address of n
printf("p1 = %dn", p1);
printf("p2 = %dn", p2);
o = *p1+*p2;
printf("*p1+*p2 = %dn", o);//point 1