DSA4-9
DSA4-9
CLASSIFICATION
-SYSTEM SOFTWARE
-APPLICATION SOFTWARE
SYSTEM SOFTWARE:
OPERATING SYSTEMS, COMPILERS, LOADERS, LINKERS, ASSEMBLERS,
DEVICE DRIVERS ETC.
APPLICATION SOFTWARE:
WHEN THE PROBLEM TO BE SOLVED IS TOO COMPLEX
WHEN DATA TO BE PROCESSED IS LARGE/ HUGE
Programming Concepts of C Language
Case sensitive language
Performs very little (almost none) limits or type checking
Highly syntax dependent (use of ;)
Provides ample opportunities to experiment and develop new styles
Preprocessor directives:
#include <stdio.h>
#include<conio.h>
#define directive
Macros:
Inline Macros
#define N 10
#define SQR(x) x*x
Multiline macros
Programming Concepts of C Language
main() : int main()/ void main() / main()
Scalar Data types:
5 basic: char,int,float,double,enum
4 modifiers: short,long,signed,unsigned
Aggregate Data types:
Arrays, structures and Unions
So in C language &a[i][j]=a+(i*n+j)*sizeof(type)
-----------------------------------------------------------------------
struct
scanf() and printf():
scanf(“%d%c%d”,&x,&y,&z);
char a[10];
scanf(“%s”,a);
Discussions Lecture 4-5:
Arrays: Collection of similar items
Struct: Collection of different but related items.
struct stu_rec{
int rollno;
char name[40];
int marks;
};
typedef struct stu_rec student;
Now we can use student in place of struct stu_rec while declaring variables.
Example: student x;
● %*[^\n] scans everything until a \n, but doesn't scan in the \n. The asterisk(*)
tells it to discard whatever was scanned.
● %*c scans a single character, which will be the \n left over by %*[^\n] in this
case. The asterisk instructs scanf to discard the scanned character.
● Both %[ and %c are format specifiers. You can see what they do. The asterisks in both
the specifiers tell scanf, not to store the data read by these format specifiers.
● fflush(stdout) is permitted to be used.
● However fflush(stdin) in undefined in ANSI C and therefore it may or may not
work.
● Very good reference material for scanf():
http://www.cplusplus.com/reference/cstdio/scanf/
Programming Concepts of C Language
Use of escape sequences in printf():
\n,\t etc….
Use of getch() & getche() in Windows C compilers
#include<conio.h>
char x;
x=getch();
Instead, we use sizeof() function to allocate bytes based on the type of the data so
that it can run on any machine.
Discussions Lecture-6
Array space allocation example:
#include<stdio.h>
int main()
{
int a[10];
int *p;
a[0]=10;
p=a;
printf("%d %d\n",p[0],a[0]);
}
10 10
Discussions Lecture-6
Password program using getch(): (for Windows compiler only)
#include<stdio.h>
#include<conio.h> x
This line not required in LINUX
int main()
{
char p[20],x;
int i=0,j;
printf("give password:");
do
{
x=getch();
x=getc(stdin); in LINUX
if (x!=13)
10 instead of 13 in LINUX (10 is LF in LINUX,
{
while13,10 is CRLF in Windows)
p[i]=x;
//printf("*");
}
i++;
}
while(x!=13);
Discussions Lecture-6
How to make a career in IT Industry
(For those who are comfortable with C programming. Those who are not, please
don’t try these).
1. Start using LINUX instead of Windows environment. I will suggest Ubuntu
Latest release.
2. Learn Java (OO Programming language) and JavaScript (OO Scripting
Language) Both these languages have C type syntax.
- Java creates applications that run in a virtual machine or browser.
- JavaScript runs in a browser only and makes your web pages more
interactive.
1. Start learning and using “Sublime Text” for all your text manipulation needs.
2. Start using “Visual Studio Code” for all your coding.
3. Learn language “Go”. See online tutorials for the same.
4. If you have learned these and use them regularly, 50% of your work for
getting a job in IT industry is done.
Programming Concepts of C Language
Conditional statements:
if ….... else …………
switch()
Break;
switch (expression)
{
case constant1:
// statements
break;
case constant2:
// statements
break;
.
.
.
default:
// default statements
}
Programming Concepts of C Language
Looping:
for(i=0; i<10; i++)
{
}
while( )
{
}
do {
} while( );
Programming Concepts of C Language ……….
Functional types of variables:
auto, static, register, extern
Functions:
-Role and concepts
-Procedures and Functions
-Parameter passing mechanisms (by value, by address/reference)
-use of Pointers
scanf and printf :
Use of & in scanf and not in printf
Examples:
Factorial
Summing the series
Tower of Hanoi
Jumping Car problem
Programming Concepts of C Language ……….
Recursion:
General format:
If (term_cond)
{
terminating_assignment;
}
else
{
recursive_definition:
}
Head recursion
Tail recursion
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
printf("%d\n",fact(5));
getch();
}
int fact(int n)
{
int f;
if (n==1)
f=1;
else
{
f=n*fact(n-1);
}
return f;
}
Reserved words in C language: