The C Language is developed by "Dennis Ritchie"(1972)at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. for creating system applications that directly interact with the hardware devices such as drivers, kernels, etc.
.In 1967, a new computer programming language was announced called as 'BCPL' which stands for Basic Combined Programming Language. ... In 1972, a great computer scientist Dennis Ritchie created a new programming language called 'C' at the Bell Laboratories. It was created from 'ALGOL', 'BCPL' and 'B' programming languages
.It can be defined by the following ways:
->Mother language
->System programming language
->Procedure-oriented programming language
->Structured programming language
->Mid-level programming language
->Write a "C" Programme to print a message on output screen
#include <stdio.h>
int main() {
printf("Hello C Programming\n");
return 0;
}
.stdio.h - standard input output headerfile
.int - return type
.# - Pre Processor
.printf and scanf functions are stored in stdio.h headerfile.
.printf and scanf are library functions.
."printf" task is a to print a message on output screen.
."scanf" task is to reads from standard input stream.
.The first programme was initiated in UNIX OPERATING SYSTEM.
.Initially, C language was developed to be used in UNIX operating system. It inherits many features of previous languages such as B and BCPL.
->Let's see the programming languages that were developed before C language.
Language Year Developed By
Algol 1960 International Group
BCPL 1967 Martin Richard
B 1970 Ken Thompson
Traditional C 1972 Dennis Ritchie
K & R C 1978 Kernighan & Dennis Ritchie
ANSI C 1989 ANSI Committee
ANSI/ISO C 1990 ISO Committee
C99 1999 Standardization Committee
."Bit" is a smallest unit in computer.
.Bit (it will store either "0" or "1")
4 bits = nibble
8 bits = 1 byte
1KB = 1024 bytes
1MB = 1024 KB
1GB = 1024MB
1TB = 1024GB
."int" is a data type it occupies 2bytes or 4bytes it depends upon compiler.
Features of C Language:
C is the widely used language. It provides many features that are given below.
1.Simple
2.Machine Independent or Portable
3.Mid-level programming language
4.structured programming language
5.Rich Library
6.Memory Management
7.Fast Speed
8.Pointers
9.Recursion
10.Extensible
Keywords
The following list shows the reserved words in C. These reserved words may not be used as constants or variables or any other identifier names.
auto 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
.printf() is one of the main output function. The function sends formatted output to the screen.
Example 1: C Output
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf("C Programming");
return 0;
}
Output:
C Programming
Example 2: Integer Output
#include <stdio.h>
int main()
{
int testInteger = 5;
printf("Number = %d", testInteger);
return 0;
}
Output:
Number = 5
Example3:float and double Output
#include <stdio.h>
int main()
{
float number1 = 13.5;
double number2 = 12.4;
printf("number1 = %f\n", number1);
printf("number2 = %lf", number2);
return 0;
}
Output
number1 = 13.500000
number2 = 12.400000
Example 4: Print Characters
#include <stdio.h>
int main()
{
char chr = 'a';
printf("character = %c", chr);
return 0;
}
Output
character = a
.scanf() is one of the commonly used function to take input from the user.
.The scanf() function reads formatted input from the standard input such as keyboards.
.Example5:Write a "C" Programme to perform sum of two numbers
#include <stdio.h>
int main() {
int a,b,c;
printf("Enter any two numbers");
scanf("%d %d", &a, &b);
c=a+b;
printf("%d",c); (or) printf("sum is = %d", c);
return 0;
}
Output:
Enter any two numbers 4 5 (or) Enter any two numbers 4 5
9 sum is = 9
Example 6: Integer Input/Output
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Output
Enter an integer: 4
Number = 4
.Example 7: Float and Double Input/Output
#include <stdio.h>
int main()
{
float num1;
double num2;
printf("Enter a number: ");
scanf("%f", &num1);
printf("Enter another number: ");
scanf("%lf", &num2);
printf("num1 = %f\n", num1);
printf("num2 = %lf", num2);
return 0;
}
Output:
Enter a number: 12.523
Enter another number: 10.2
num1 = 12.523000
num2 = 10.200000
.Example 8: C Character I/O
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c",&chr);
printf("You entered %c.", chr);
return 0;
}
Output:
Enter a character: g
You entered g
->ASCII - American Standard Code for information interchange.
.ASCII value represents the English characters as numbers, each letter is assigned a number from 0 to 127.
For example, the ASCII value for uppercase Q is 81.
.Example 9: ASCII Value
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c", &chr);
// When %c is used, a character is displayed
printf("You entered %c.\n",chr);
// When %d is used, ASCII value is displayed
printf("ASCII value is %d.", chr);
return 0;
}
Output:
Enter a character: g
You entered g.
ASCII value is 103.
.I/O Multiple Values
Here's how you can take multiple inputs from the user and display them.
Example10:
#include <stdio.h>
int main()
{
int a;
float b;
printf("Enter integer and then a float: ");
// Taking multiple inputs
scanf("%d%f", &a, &b);
printf("You entered %d and %f", a, b);
return 0;
}
Output:
Enter integer and then a float: -3 3.4
You entered -3 and 3.400000
->Here's a list of commonly used C data types and their format specifiers.
Data Type Format Specifier
int %d
char %c
float %f
double %lf
short int %hd
unsigned int %u
long int %li
long long int %lli
unsigned long int %lu
unsigned long long int %llu
signed char %c
unsigned char %c
long double %Lf
Social Plugin