UNIT-1
UNIT-1
Computer Systems:
The input device is usually a keyboard where programs and data are entered into
the computers. Examples of other input devices include a mouse, a pen or stylus, a
touch screen, or an audio input unit.
The central processing unit (CPU) is responsible for executing instructions such as
arithmetic calculations, comparisons among data, and movement of data inside the
system.
The output device is usually a monitor or a printer to show output. If the output is
shown on the monitor, we say we have a soft copy. If it is printed on the printer, we
say we have a hard copy.
Auxiliary storage, also known as secondary storage, is used for both input and
output. It is the place where the programs and data are stored permanently. When
we turn off the computer, or programs and data remain in the secondary storage,
ready for the next time we need them.
2. Computer Software :
• The software is the collection of programs (instructions)
• Computer software is divided in to two broad categories: system software
and application software.
System software manages the computer resources .It provides the interface
between the hardware and the users.
Application software, on the other hand is directly responsible for helping users
solve their problems.
Computing Environments:
Computing Environment is a collection of computers / machines, software, and
networks that support the processing and exchange of electronic information meant
to support various types of computing solutions.
Types of Computing Environments:
1. Personal Computing Environment
2. Time sharing Environment
3. Client Server Computing Environment
4. Distributed Computing
Personal Computing Environment:
Computer Languages:
These are the languages which are used to give instructions to computer to perform
some task.
1.Machine Language
2.Assembly Language
1.Machine language:
It is also called as binary language because it only support the binary value.
Advantages:
• Execution is faster because the programmer written the code using 0’s and
1’s can be directly understandable by computer.
• No translator is required.
Disadvantages:
• It is very difficult to read,understand,write program in machine language.
• It is very difficult to remember the machine language.
• It is machine dependant language
2.Assembly Language:
Advantages:
Disadvantages:
Advantages:
Disadvantages:
=0+0+32+16+8+0+0+1
=57
Decimal to binary conversion:
• Decimal number is:(771)10
Decimal to hexadecimal number system:
Ex:1Decimal Number is : (12345)10
DATA TYPES :
• Data type represents the type of data we use in our program and how much
memory memory is used to store that data.
• Data types are classified as
o Primitive data types
o Derived data types and
o User defined data types
Primitive data types/basic data types:
• These data types are built-in or predefined data types and can be used
directly by the user to declare variables.
• C supports the following data types.
#include <stdio.h>
int main ()
{
int x,y,z;
x = 20;
y = 30;
z = x + y;
printf ("value of x = %d, y = %d and z = %d\n", x, y, z);
return 0;
}
Global variables:
• Variables that are declared outside of a function block and can be accessed
inside the function is called global variables.
2.Global scope
• Global variables are defined outside a function or any specific block, in most
of the case, on the top of the C program. These variables hold their values all
through the end of the program and are accessible within any of the functions
defined in your program.
• Any function can access variables defined within the global scope, i.e., its
availability stays for the entire program after being declared.
#include <stdio.h>
int z;
int main ()
{
int x,y;
x = 20;
y = 30;
z = x + y;
printf ("value of x = %d, y = %d and z = %d\n", x, y, z);
return 0;
}
Storage classes:
• A variable mainly depends on
1.datatype
2.Storage class
• Datatype represents
1.what type of data has to be stored and
2.how much memory is allocated to store that data
• Storage class represents 4 things:
1.Storage Place
2.Default Value
3.Scope
4.Lifetime
Syntax:
Storageclass datatype variable name;
• There are four types of storage classes in C
1.Automatic
2.External
3.Static
4.Register
1.Automatic:
• The keyword used for defining automatic variables is auto.
Synatx:
auto datatype variablename;
Example program:
#include <stdio.h>
int main()
{
int a; //auto
char b;
float c;
printf("%d %c %f",a,b,c); // printing initial default value of automatic variables a, b,
and c.
return 0;
}
2.Static:
• The keyword used to define static variable is static.
Synatx:
static datatype variablename;
Example program:
#include<stdio.h>
static char c;
static int i;
static float f;
static char s[100];
void main ()
{
printf("%d %d %f %s",c,i,f); // the initial default value of c, i, and f will be printed.
}
3.Register:
The register keyword is used for the variable
Synatx:
register datatype variablename;
Example program:
#include <stdio.h>
int main()
{
register int a; // variable a is allocated memory in the CPU register. The initia
l default value of a is 0.
printf("%d",a);
}
4.External:
Keyword used is extern
Synatx:
extern datatype variablename;
Example program:
#include <stdio.h>
int a;
int main()
{
extern int a; // variable a is defined globally, the memory will not be allocated to a
printf("%d",a);
}
Type Qualifiers:
• In C programming language, type qualifiers are the keywords used to modify
the properties of variables. Using type qualifiers, we can change the properties
of variables. The c programming language provides two type qualifiers and
they are as follows...
• const
• volatile
() left–to–right
[]
—>
++(postfix) right–to–left
––(postfix)
++(prefix) right–to–left
––(prefix)
+(unary) – (unary)
!~
(type)
*(indirection)
&(address)
Sizeof
*/% left–to–right
+– left–to–right
> >=
== != left–to–right
& left–to–right
^ left–to–right
| left–to–right
&& left–to–right
|| left–to–right
?: right–to–left
= right–to–left
+= –=
*= /=
%= &=
^= |=
<<= >>=
,(comma) left–to–right
Ex:
Float x;
Int y=3;
X=y;
Output:
X=3.0000000
This is also known as promotion(when lower level datatype is promoted to
higher level)
Example program for implicit type conversion:
#include<stdio.h>
#include<conio.h>
main()
{
float x=90.99;
char ch=’a’;
int i=95;
i=x;
printf(“I value is %d\n”,i);
x=i;
printf(“x value is %f\n”,x);
i=ch;
printf(“i value is %d\n”,i);
getch();
}
Disadvantages of implicit type conversion:
• In implicit type conversion,while converting the data is lost sometimes.
Ex:
• When a float value is converted to an integer value,the fractional part is
truncatenated.
• When a double value is converted to float value,rounding of digits is done.
• When a longint is converted into integer,the excess higher order bits are
removed.
All these changes may cause incorrect results.
Type casting/explicit type casting:
• Type casting is done explicitly by the programmer.
• Type casting is also known as forced conversion.
• It is done when the value of a higher datatype has to be converted into the
value of a lower data type.
Syntax:
(datatype)expression;
Ex; int a=70,b=20;
float res;
res=(float)a/b;
Example program for explicit type conversion:
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
float avg;
clrscr();
printf(“enter 2 integer values\n”);
scanf(“%d%d”,&a,&b);
avg=(a+b)/2;
printf(“the average before type casting is %f\n”,avg);
avg=(float)(a+b)/2;
printf(“the average after type casting is %f\n”,avg);
getch();
}
Command line arguments:
We are giving the arguments in the command line ie.,without using the input
function(i.e.,scanf)
All the arguments passed in the command line should be passed through main()
Syntax:
main(int argc,char *argv[])
here
argc-argument count which is always a integer value.
argv-argument value which is character data type.
Example program:
main(int argc,char *argv[])
{
printf(“%d”,argc);
printf(“%s”,argv[0]);
printf(“%s”,argv[1]);