0% found this document useful (0 votes)
71 views15 pages

03 HelloWorld in C'

This document provides an introduction to programming in C language. It discusses the history and development of C, including how it was designed in the 1970s and standardized in later decades. It also describes some key characteristics of C, such as its case sensitivity and support for structured programming with functions. The document demonstrates how a simple C program is created by writing source code, compiling it, and linking and running the executable file. It provides examples of basic C programs that print text and accept user input.

Uploaded by

niharranjanroy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views15 pages

03 HelloWorld in C'

This document provides an introduction to programming in C language. It discusses the history and development of C, including how it was designed in the 1970s and standardized in later decades. It also describes some key characteristics of C, such as its case sensitivity and support for structured programming with functions. The document demonstrates how a simple C program is created by writing source code, compiling it, and linking and running the executable file. It provides examples of basic C programs that print text and accept user input.

Uploaded by

niharranjanroy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to programming in C

Nihar Ranjan Roy


History of C Programming language
The C programming language was designed by Dennis Ritchie at Bell
Laboratories in the early 1970s
In 1983 the American National Standards Institute (ANSI) began the
standardization process
In 1989 the International Standards Organisation (ISO) continued the
standardisation process
In 1990 a standard was finalised, known simply as Standard C In 1990 a standard was finalised, known simply as Standard C
Everything before this is known as K&R C Traditionally used for
systems programming.
Main source of documentation of K& R C
The C Programming Language, by Brian Kernighan and Dennis Ritchie,
2
nd
Edition, Prentice Hall
Referred to as K&R
Nihar Ranjan Roy 2
Characteristics of C Language
It recognizes the difference between lowercase and uppercase letters.
It can be written with free format
Can write as many instructions as in a single line
Its a structured programming language
During execution the control falls from the line at the top to the
next line below it next line below it
Program consists of smaller units called functions.
Nihar Ranjan Roy 3
Building a C program
#include<stdio.h>
int main(void)
{.
..
}
Text Editor
Compiler
01001001

1110101
Programmer
Source Code
Object Code
___________
________________
________________
________________
_
Linker
Loader
1110101
1110100001001
.
111010000111101
Executable
Code
Results
Nihar Ranjan Roy 4
Writing and editing programs
Use any text editor (Ascii) available on your computer.
Example: windows (Edit,TC IDE,Notepad), Linux( Vi,Vim,emacs etc.)
Compiling (windows)
With IDE ( Turbo C)
Press Alt+F9
Command prompt
Issue the following command tcc filename.c Issue the following command tcc filename.c
Linking
Running the program
Windows
With IDE
Press CTRL+F9
Command Prompt
Issue the following command filename(hit enter)
Linux
Issue the following command ./a.out or ./outputfilename( hit enter)
Nihar Ranjan Roy 5
Structure of a C program
/* Preprocessor directives */
/* Global declarations */
#include <stdio.h>
int main(void)
{
int main(void)
{
/*Local declarations
Statements*/
}
/* other functions as required */
{
printf("Hello");
return 0;
}
Nihar Ranjan Roy 6
My First C Program
#include <stdio.h> /* comment */
int main(void)
{
tells compiler about st standdard iinput and ooutput functions (i.e. printf + others)
main function
{
printf("Hello");
return 0;
}
begin
end
flag success
to operating
system
Nihar Ranjan Roy 7
Command Prompt(Windows) : Compiling & Running
Nihar Ranjan Roy 8
Turbo C IDE
Nihar Ranjan Roy 9
The Format of C
Statements are terminated with
semicolons
Indentation is ignored by the compiler.
C is case sensitive - all keywords and
Standard Library functions are lowercase.
Strings are placed in double quotes
#include <stdio.h>
/* comment */
int main(void)
{
printf("Hello");
Strings are placed in double quotes
Newlines are handled via \n
Nihar Ranjan Roy 10
printf("Hello");
return 0;
}
Problem
Write a program in C which asks the user what is your name?. Accepts
users name and greets him as Hello,xxxx where xxxx is the name of
the user.
What is your name?
Nihar
Nihar Ranjan Roy 11
Nihar
Hello, Nihar
2
nd
Program
char name [30] ;
declares a variable named name, which
can hold a string of up to 29
characters (letter, digit, punctuation,
etc.).
#include<stdio.h>
void main()
{
printf ("What's your name? ");
Nihar Ranjan Roy 12
read your name into the variable name.
printf ("What's your name? ");
scanf("%s",name);
printf("Hello, %s\n",name);
}
Problem
Write a program which accepts two integer numbers and displays its
sum.
Enter two numbers:
6 7
The sum is 13
Nihar Ranjan Roy 13
3
rd
Program
#include<stdio.h>
void main ()
{
int a,b,sum;
printf("Enter two numbers: ");
We have made five changes to the
original program. We have
1. replaced the line defining name with one
defining other variables (a, b, and sum, all
integers)
2. changed the message in the printf
Nihar Ranjan Roy 14
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
sum = a + b;
printf("The sum is %d \n",sum);
}
2. changed the message in the printf
statement
3. changed the format string and variable
list in the scanf statement
4. added the assignment statement sum = a +
b;
5. changed the format string and argument
list in the final printf statement
Conclusion & Queries
Nihar Ranjan Roy 15

You might also like