Programming in C

Lecture 1: INTRODUCING C (1)

CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta

Next Lecture: Introducing C (2)


Lecture Outline

Recommended reading
Aims and Objectives
What is C?
Preamble
The first C Program
Writing more complex programs
Group Exercise


Recommended Reading (aka ASSIGNED TEXTBOOK)


Aims and Objectives

Of the course

Of the lecture


What is C?


Preamble

a.out


The first C Program

	#include <stdio.h>

	main()
	{
		printf("hello, world\n");
	}

The Program line by line

	#include <stdio.h>

	main()
	{
	}

	printf("hello, world\n");


Writing more complex programs

Variables

Some Variable types

char - a single character (one byte)
int - an integer
short - a short integer
long - a long integer
float - a floating point number
double - a double-precision float

Assignment

variable = expression

a = b + 5

Conditionals

expression operator expression

a <= b

Looping constructs (simple)

	while ( conditional ) {
		statements ;
	}

Comments

	/* free text */

	/* some
	free
	text
	*/

is ok, but

	/* some free text
	/* some more free text */
	*/

is illegal, and will generate a syntax error (/* cannot be used inside a comment!)

        // ignore text to end of line

Formatted printing

printf("format"[, expression [, expression]]);


Exercises


Next Lecture...

Introducing C (2)