Lecture2hu - 1 ELE108 Introduction to Programming Dr. Ali...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 ELE108 Introduction to Programming Dr. Ali Ziya Alkar Dr. Mehmet Demirer 2 Outline • Overview of C • General form of a C program • C Language Elements 3 History & Philosophy • C is developed in 1972 by Dennis Ritchie at the AT&T Bell Laboratories for use with the Unix. • C is a minimalistic programming language. • The most commonly used programming language for writing system software. • Machine independent: by minimal change in source code, can be compiled in a wide variety of platform and operating system. 4 Why C? • Many, many companies/research projects do all their programming in C. • Small, compact code. • Produces optimized programs that runs faster. • Low-level access to computer memory via machine addresses and pointers. • Low level (BitWise) programming readily available. • Can be compiled on a variety of computers. 5 What’s Missing? • No Objects. • Poor error detection which can make it difficult to use for the beginner ¡ No automatic garbage collection. ¡ No bounds checking of arrays and allocated memory segments. ¡ No exception handling. • No native support for multithreading and networking, though these facilities are provided by popular libraries • No standard libraries for graphics and several other application programming needs 6 A Simple, Example C Program /* helloworld.c */ #include <stdio.h> int main(void) { printf("Hello World!\n"); return(0); } • Every C program has a main function. It is very much the same as the main method in a Java class. • printf is also the name of a function. It can do much the same as Java's System.out.print . • This program can use the printf function, because of the line #include <stdio.h> in the source code. This line is similar to Java's import java.io.* 7 General Form of a C program • Preprocessor directives are instructions to C Preprocessor to modify The text of a C program before compilation. • Every variable has to be declared first. • Executable statements are translated into machine language and eventually executed. • Executable statements perform computations on the declared variables or input/output operations. 8 Miles to Kilometers conversion 9 C Language Elements • Preprocessor Directives • Comments • The “main” function • Variable Declarations and Data Types • Executable Statements • Reserved Words • Identifiers 10 Preprocessor Directives /* Converts distances from miles to kilometers */ #include <stdio.h> /* printf, scanf definitions */ #define KMS_PER_MILE 1.609 /* conversion constant */ int main(void) { double miles, //distance in miles kms; //equivalent distance in kilometers //Get the distance in miles printf("Enter the distance in miles> "); scanf("%lf", &miles); //Convert the distance to kilometers kms = KMS_PER_MILE * miles; //Display the distance in kilometers printf("That equals %f kilometers.\n", kms); return (0); } 11 Preprocessor Directives • Preprocessor directives are commands that give instructions to the C preprocessor.instructions to the C preprocessor....
View Full Document

Page1 / 41

Lecture2hu - 1 ELE108 Introduction to Programming Dr. Ali...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online