Presentation is loading. Please wait.

Presentation is loading. Please wait.

Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:

Similar presentations


Presentation on theme: "Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:"— Presentation transcript:

1 Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors: – Semantic errors (check function arguments) – Logic errors manual trace add debugging code to check variables use print statements check expressions; order of precedence, operation rules

2 Reading input from terminal scanf() read data typed at the keyboard convert the data to its internal form store it into an object How can this be done? scanf() is a function Functions cannot directly access a variable by its name defined in another function If scanf() cannot directly access a variable in main(), it cannot assign a value to that variable

3 Address of variable Use address of variable to access object int x; scanf(“%d”,&x); Scanf command uses a format string similar to printf command. %d indicates variable is an integer. Scanf reads input, converts it to an internal form, and stores it into an integer object whose address is given by the next unmatched argument. Value read is stored into the object whose address is &x and the value is stored into x.

4 Additional scanf() comments scanf() is buffered as the input data is not read until a full buffer has been entered, indicated by a return key (a newline). scanf() is free form as it ignores blanks. The first data item found in the input will be converted and stored in the address provided. Likewise, scanf() will not return until it has converted the requested number of data items. Additional data in the buffer is not affected by scanf()


Download ppt "Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:"

Similar presentations


Ads by Google