C" History: Type Storage Size Value Range
C" History: Type Storage Size Value Range
History
The language B was developed in 1969-70 by Ken Thompson derived directly
from Martin Richards BCPL. B, a high-level language was used for
development of the UNIX system with few lines of code. But, B doesnt
support data-types and structures.
In 1971-73 Dennis M. Ritchie turned the B language into the C language, by
using the syntax of B language and adding few features to it. C was used to
program an operating system, especially Unix Kernel was written in C. C is
known for its features like Reliability, Portability, Flexibility, Interactivity,
Modularity, Efficiency and Effectiveness.
Why C, a middle level language??
It combines the elements of high-level languages with the
functionalism of assembly language.
It supports Inline Assembly Language Programs by which system
registers can be accessed.
It is used to access memory using pointers and is more user
friendly.
Why C, a structured oriented programming??
To solve a large problem, C programming language divides the problem into
smaller modules called functions or procedures each of which handles a
particular responsibility.
Definitions
1. Data Types: It is used for declaring variables or functions of different
types.
Type
Storage size
Value range
char
1 byte
-128 to 127 or 0 to 255
unsigned char 1 byte
0 to 255
signed char
1 byte
-128 to 127
int
2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short
2 bytes
-32,768 to 32,767
0 to 65,535
-2,147,483,648 to 2,147,483,647
0 to 4,294,967,295
int x=100
int main()
{
int x=50;
printf("%d",x);
}
else
long
switch
break
enum
register
typedef
case
extern
return
union
char
float
short
unsigned
const
for
signed
void
continue
goto
sizeof
volatile
default
if
static
while
do
int
struct
_Packed
double
7. Identifiers: Names given for identifying variables, functions and arrays are
termed as Identifiers.
8. Operators: These are the symbols used for performing logical and
mathematical operations. Operators join individual constants and variables to
form an expression. C language provides several operators like,
Arithmetic operators
Assignment operators
Relational operators
Logical operators
Bit wise operators
Conditional operators (ternary operators)
Increment/decrement operators
Special operators
9. Strings: These are array of characters represented using double quotes
and ends with null (\0).
10. Arrays: Arrays are collection of variables of same datatype having a
contiguous memory allocation.
Types:
One dimensional array
Multi dimensional array
11. You can also represent char and int in hexadecimal and octal notations.
hex num is preceded by 0x or 0X, For octal, its preceded by 0 (zero). you
cant represent a float num as hexa and octal.
12. Basic precedence order : unary minus has the highest priority and then
the order is *,/,%,+,- and then assignment operators.
13. scanf( ) and printf ( ) :
These are the standard library functions which is used to get the input from
the user and print the output on the screen.
Eg : printf( enter your age);
scanf( %d,&n);
In scanf the variable name must be preceded by address of operator (&).
14. printf( ) and sprintf ( ) :
printf( ) is used to display the ouput on screen whereas sprintf( ) is used to
store the output to an array.
15 Can you guess the output of this code :
?
#include <stdio.h>
int main(void) {
printf("size of '5' is %d \n", sizeof('5'));
printf("size of 5 is %d \n", sizeof(5));
printf("size of 5.0 is %d \n", sizeof(5.0));
return 0;
}
The output is 2 2 -2 -2
% operator returns the reminder on dividing the first integer by the second. If
any one of them is negative,then the result takes the sign of the numerator.
17. What is the output of the following code?
?
#include <stdio.h>
int main(void) {
float a=7,b=2;
int c;
c=a%b;
printf("%d",c);
return 0;
}
Here the output is definitely not 50000. Surprised? Here the value of
50000*50000 exceeds the range of an integer.
20. Wed recommend you to use visual studio or gcc compiler. Otherwise use
online compiler indeone or codepad.org.
Try these simple programs.
1. Write a program to compute the seconds from the given age.
2.Write a program to compute simple interest and compound interest from the
given principal amount,interest rate and time period.