C Programming Language
Mo’meN Ali
Course Contents
• Introducing C.
• Data and C.
• Character Strings and formatted input/output.
• Operators, Expressions and Statements.
• C Control Statements: looping.
• C Control Statements: Branching and jumping.
• Character input/output and input validation.
• Functions.
• Arrays and Pointers.
• Character Strings and String Functions.
Introducing C language
The seven steps of programming
1 - Define the program objectives.
2 - Design the program.
3 - Write the code.
4 - Compile.
5 - Run the program.
6 - Test and debug the program.
7 - Maintain and modify the program.
C Strengths
• Efficiency.
• Portable.
• Power & Flexibility.
• Fast.
• Favourable language when interacting with hardware.
• Small and Compact.
C Weakness
• Not OOP.
• Programming in C needs responsibility.
How Does a C Program looks like ?!
#include <stdio.h>
int main(void)
{
printf("Concrete contains gravel and cement.n");
return 0;
}
Output
Concrete contains gravel and cement.
/* a simple program */
#include <stdio.h>
int main(void)
{
int num; /* define a variable called num */
num = 1; /* assign a value to num */
printf("I am a simple "); /* use the printf() function */
printf("computer.n");
printf("My favorite number is %d because it is first.n",num);
return 0;
}
Output
I am a simple computer.
My favorite number is 1 because it is first.
Explanation
• #include /* Preprocessor instructions. */
• int main(void) /* main is the first function to be
called always. */
• Statements. /* functions are made up of
statements.*/
• Function: a(), b(), c() /* usually we write another
functions within a program. */
// I am a comment.
/* I am the twin brother of comment. */
// fathm_ft.c -- converts 2 fathoms to feet
#include <stdio.h>
int main(void)
{
int feet, fathoms;
fathoms = 2;
feet = 6 * fathoms;
printf("There are %d feet in %d fathoms!n", feet, fathoms);
printf("Yes, I said %d feet!n", 6 * fathoms);
return 0;
}
Output
There are 12 feet in 2 fathoms!
Yes, I said 12 feet!
ISO/ANSI C Keywords
auto enum restrict unsigned
break extern return void
Case float short volatile
char for signed while
const goto sizeof _Bool
continue if static _Complex
default inline struct _Imaginary
do int switch
double long typedef
else register union

1 introducing c language

  • 1.
  • 2.
    Course Contents • IntroducingC. • Data and C. • Character Strings and formatted input/output. • Operators, Expressions and Statements. • C Control Statements: looping. • C Control Statements: Branching and jumping. • Character input/output and input validation. • Functions.
  • 3.
    • Arrays andPointers. • Character Strings and String Functions.
  • 4.
  • 6.
    The seven stepsof programming 1 - Define the program objectives. 2 - Design the program. 3 - Write the code. 4 - Compile. 5 - Run the program. 6 - Test and debug the program. 7 - Maintain and modify the program.
  • 7.
    C Strengths • Efficiency. •Portable. • Power & Flexibility. • Fast. • Favourable language when interacting with hardware. • Small and Compact.
  • 8.
    C Weakness • NotOOP. • Programming in C needs responsibility.
  • 9.
    How Does aC Program looks like ?! #include <stdio.h> int main(void) { printf("Concrete contains gravel and cement.n"); return 0; }
  • 10.
  • 11.
    /* a simpleprogram */ #include <stdio.h> int main(void) { int num; /* define a variable called num */ num = 1; /* assign a value to num */ printf("I am a simple "); /* use the printf() function */ printf("computer.n"); printf("My favorite number is %d because it is first.n",num); return 0; }
  • 12.
    Output I am asimple computer. My favorite number is 1 because it is first.
  • 13.
    Explanation • #include /*Preprocessor instructions. */ • int main(void) /* main is the first function to be called always. */ • Statements. /* functions are made up of statements.*/ • Function: a(), b(), c() /* usually we write another functions within a program. */ // I am a comment. /* I am the twin brother of comment. */
  • 14.
    // fathm_ft.c --converts 2 fathoms to feet #include <stdio.h> int main(void) { int feet, fathoms; fathoms = 2; feet = 6 * fathoms; printf("There are %d feet in %d fathoms!n", feet, fathoms); printf("Yes, I said %d feet!n", 6 * fathoms); return 0; }
  • 15.
    Output There are 12feet in 2 fathoms! Yes, I said 12 feet!
  • 16.
    ISO/ANSI C Keywords autoenum restrict unsigned break extern return void Case float short volatile char for signed while const goto sizeof _Bool continue if static _Complex default inline struct _Imaginary
  • 17.
    do int switch doublelong typedef else register union