C language--Introduction

C language--Introduction
History
• 1970: B by Ken Thompson at AT&T Bell
Lab
• 1972: C by Dennis Ritchie and Ken
Tompson at At&T Bell Lab for UNIX
• 1978: “The C Programming Language” by
Brian Kernighan and Dennis Ritchie (K&R
C)
• 1988: ANSI C
The First Program
• #include <stdio.h>
• main( ) {
printf(“Hello, World!\n");
}
How to use printf()
•
•
•
•
printf("Hello");
printf("Hello\n");
printf("%d", b);
printf("The temperature is ");
printf("%d", b); printf(" degrees\n");
• printf("The temperature is %d
degrees\n", b);
• printf("%d + %d = %d\n", a, b, c);
How to use printf()
•
•
•
•
int (integer values) uses %d
float (floating point values) uses %f
char (single character values) uses %c
character strings (arrays of characters,
discussed later) use %s
How to use scanf()
• scanf("%d", &b);
– int uses %d
– float uses %f
– char uses %c
– character strings use %s
• scanf("%d %d",&a, &b);