tutorial02 - CS1010E Programming Methodology Semester 1...

Info iconThis preview shows pages 1–2. 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
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS1010E Programming Methodology Semester 1 2011/2012 Week of 29 August – 2 September 2011 Tutorial 2 Basic C Elements 1. The Edit–Compile–Run cycle in program development is second nature to all pro- grammers. In essence, we use an editor ( vim ) to type out the source code/program, which is then compiled via a compiler ( gcc ) to machine executable instructions which is, in turn, executed/run. Experience the Edit–Compile–Run cycle by typing out the following program, compiling and executing it. Take note of any errors and rectify the program accordingly. #include <stdio.h> int main(void) { int cur, prev1 = 1, prev2 = 1; cur = prev1 + prev2; prev2 = prev1; prev1 = cur; cur = prev1 + prev2; prev2 = prev1; prev1 = cur; cur = prev1 + prev2; prev2 = prev1; prev1 = cur; printf("cur is %d; prev1 is %d; prev2 is %d\n", cur, prev1, prev2); return 0; } 2. Being able to trace through the execution of a program without going through the Edit– Compile–Run cycle is known as program tracing . Program tracing involves building up a mental model of program execution in your mind. By tracing a program, you will gain a stronger understanding of the program execution flow and improve your programming skill. Trace the execution of the program in question 1, paying particular attention to variable declarations and changes to the values of the variables. Verifyattention to variable declarations and changes to the values of the variables....
View Full Document

This note was uploaded on 12/13/2011 for the course ELECTRICAL CS1010E taught by Professor Henrytan during the Spring '11 term at National University of Singapore.

Page1 / 4

tutorial02 - CS1010E Programming Methodology Semester 1...

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

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