Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Overview in C , some basic stuff, Lecture notes of C programming

Notes in C for beginners , introduction to the command line

Typology: Lecture notes

2016/2017

Uploaded on 08/28/2017

byron-ramon-banzon
byron-ramon-banzon 🇵🇭

5

(1)

5 documents

1 / 45

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EEE 11: Lecture 2
C Overview
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Overview in C , some basic stuff and more Lecture notes C programming in PDF only on Docsity!

EEE 11: Lecture 2

C Overview

Meet 'P'

● Can move up, down, left and right

● Can move along the following items

− Road

− Bridge

● Understands only the following:

− “U” - move up one step

− “D” - move down one step

− “R” - move right one step

− “L” - move left one step

Programming Language

● Set of instructions or commands that the machine

can understand

− Allows you to control the computer

● Has is own grammar called Syntax

● Example:

− Apple red is a fruit

− Form a circle and make it straight

The C Programming Language

● Medium-level programming language (higher level than

assembly language)

● Developed in the 1970's by Ken Thompson and Dennis Ritchie

− Ritchie is one of the authors of “The C Programming Language”

Sample 02-

Hello there!

Displays Hello there

#include <stdio.h>

int main (void)

printf(“Hello there!\n”); /* Display text */

return 0;

Sample code 02-01: Simple C code

Preprocessor directive

Comments

Statements

Main function

Sample 02-

a = 10

Display a

Variable Declarations

● Define the name and the kind of information stored

● REQUIRED BEFORE USE

● Variable

− A name associated with a data whose value can change during program execution

● Data Type

− A name or label for a set of values and operations that can be performed on those values e.g. An integer can be added, subtracted, multiplied, etc

Variable Declaration Formats

● Syntax

<variable_list>; *variable_list are comma-separated names

● Examples

/* Single declaration */ int count;

/* multiple declarations */ float miles, kms; int number1,

number2, /* can span several lines */

number3; /* not recommended */

Identifier Rules

● Must consist only of

− letters [A,..,Z,a,...,z] − Digits [0,..,9] − Underscores _

● Cannot begin with a digit

− Valid identifiers: _abc, letter1, letter2, inches, Hello, VARiable − Invalid identifiers: 1_a, .name, (number

● Case-sensitive

− inches and INCHES are not the same

● Some compilers consider only the first 31 characters

Review

Classify the words as

(a) valid identifiers (b) invalid identifier

9teen double sqrt

#insert return this_is_an_example

printf xyz123 void

G Sue's

Reserved Identifiers

● Words that have special meaning in C

− Also known as Keywords

● Standard Identifiers

− Names that are not reserved but are used by the C standard libraries

Standard Identifiers

● Names of functions defined in the standard libraries

● Can be redefined and used for other purposes

− NOT RECOMMENDED!

stdio.h math.h stdlib.h printf sqrt atof scanf exp atoi getc sin strtod

Use consistent naming style

(see our resources page for sample)

● Constants are all UPPERCASE

● User-defined identifiers are in lowercase

− No mixed cases (eg maxHeight)

● Assign meaningful identifier names

− Keep it short (e.g. SMS lingo) − Single characters are OK for short codes

● Do not choose names that are similar to each other

− LARGE and large − xcoord and x_coord

● BE CONSISTENT!