[Legacy Content] This page contains very old information, which might not be valid anymore, they are only kept here for legacy purposes.
if you have any inquiries, feel free to contact me! Click here

Structured Programming - Lesson 1

Created: Monday, 12 August 2013 Written by Ehab Eldeeb

Data Types

Data Type is a reserved word for any programming language that tells the program what type of data you are using

  • Integer (Whole Number) : int, short, long
  • Floating Point (Fractions) : float, double
  • Character (letter or symbol) : char
  • For a whole word you will need to use "String" .. it will be covered later on in the next course "Programming Applications"

 

Identifiers

- An identifier is the name used for a data object (a variable or a constant), or for a function,  in a C program.
- Note that it's case-sensitive (Ehab is not ehab .. they are different)
- using meaningful identifiers is a good thing for yourself so you can understand what you are doing

an identifier must start with a letter or underscore .. you can't begin your identifier with a number, and be followed by zero or more letters
(A-Z, a-z), digits (0-9), or underscores

It's okay to use these examples for an identifier:

  • age_of_person
  • taxRateY2K
  • PrintHeading
  • ageOfHorse
  • TeMpeRaTuRe

While it's NOT okay to use these words as identifiers:

  • age# (symbols are not allowed)
  • 2000TaxRate (Cannot start with a number)
  • int (data types cannot be used as identifiers)

 

Place Holders

%d %f %lf %c ... what are those?

Example:
int age = 8;
printf( “ The age is %d years “, age );
     This will print out "The age is 8 years"
You will understand more when we get into writing an actual program

 

Escaping

\n .. New Line
Example: printf("My name is \n Ehab");
This will print out "My Name is " on a line, and "Ehab" on the line under it

\t .. tabbed space (Just like if you press "space" 5 times)

 

Comments

You can write a comment inside your program using this tag /* .......... */
Example: printf("Hello World"); /* Print out hello world message */
the comment "Print out hello world message" will be seen in the source code, but will not be displayed in the actual application

 

Example Program "Hello World"

#include <stdio.h>
#include <conio.h>

void main(){
printf("Hello World");
getch();
}

... That's it :D

One Last thing ... Programming Errors

Syntax errors : detected by complier

  • Missing semicolons ;
  • Undeclared variables,…etc

 

Run-time errors

  • detected during execution. E.g. division by zero

 

Logical errors

  • Due to faulty algorithm .. example "2 + 2" is written in the program variable1 - variable2

 

.... This was the introduction to C Programming
For sure, you will understand better in the lecture, this article is just for reference