C Programming Contd
C Programming Contd
makes input
and output available
#include <stdio.h>
to us
header
int main(void)
{
printf("This is my first C program.\n");
return(0);
}
return 0; }
} }
C Program Phases
• Editor - code by programmer
• Compiling using gcc:
– Preprocess – expand the programmer’s code
– Compiler – create machine code for each file
– Linker – links with libraries and all compiled
objects to make executable
• Running the executable:
– Loader – puts the program in memory to run it
– CPU – runs the program instructions
Copyright © Pearson, Inc. 2013. All
Rights Reserved.
Copyright © Pearson, Inc. 2013. All
Rights Reserved.
Run First Program
• Write in notepad++
• Transfer with Filezilla
• Connect to panther as terminal (putty) using
SSH (Secure Shell)
• More filename to see the file
• gcc filename -o filename without c -g (ex:
gcc hello.c -o hello -g )
• ./hello
Using variables
#include <stdio.h>
int main(void)
{
int sum, value1, value2, value3;
float average;
value1 = 2;
value2 = 4;
value3 = 6;
sum = 2 + 4 + 6;
average = sum / 3;
printf("The average of %d , %d, %d is %f\n", value1,
value2, value3, average);
return(0);
}
int main(void)
{
int value1, value2, value3;
float sum, average;
comments
Character Data
• All of our programs so far have used
variables to store numbers, not words.
• We can store one or more characters by
writing:
char x, s[10];
– x can hold one and only one character
– s can hold up to nine characters (reserving 1 for
ending null)
• For now, we use character data for input and
output only.
A program that uses a character variable
#include <stdio.h>