Understanding Valid Identifiers and Syntax Errors in C Programming
This document discusses various scenarios related to valid identifiers and syntactic errors in C programming. It includes exercises on identifying valid variable names, tracing syntax errors in given code examples, and writing correct data type declarations and assignments. Additionally, it covers the use of preprocessor directives. The content highlights the significance of good coding practices by providing practical examples to enhance understanding of basic data types and error identification in programming.
Understanding Valid Identifiers and Syntax Errors in C Programming
E N D
Presentation Transcript
EXERCISE IN CLASS CHAPTER 3
PART 1 IDENTIFIER
SCENARIO 1 • record1 • 1record • file_3 • return • $tax • Name • name and address • name-and-address • name_and_address • 123-45-6789 Determine which of the following are valid identifiers. If invalid, explain why.
SCENARIO 2 #include <stdio.h> void main() { int1st, second, third; float fun, Fun; char x, initial name, my-name; Second = 8; Fun=10.2 fun = x; } Trace all the syntax error(s) in below program:
PART 1 BASIC DATA TYPE
SCENARIO 1 Write appropriate declarations and assign the given initial values for each group of variables: • Floating-point variables: a = -8.2, b = 0.005 • Integer variables: x = 129, y = 87, z = -22 • Character variables : c1 = ‘w’, c2 = ‘&’
SCENARIO 2 Identify the syntactic errors in the following program. Then rewrite the correct program. #include <stdio.h> void main() • { integer a; • floating-point b; • character c; • printf(“End.”); }
SCENARIO 3 • Write the #define preprocessor directive for a program that has the constant macro HOURLY_WAGES (5.50). • Rewrite the following program that uses variables with memory constants. • #include<stdio.h> • void main() • { float weight = 30.5; • intproduct_code = 1000;}