0% found this document useful (0 votes)
1 views3 pages

Programming Concepts Answers

The document provides a comprehensive overview of programming concepts including compilers, variables, operators, loops, and error detection. It includes definitions, examples, and coding problems related to if-else statements, switch cases, and loops. Additionally, it covers naming conventions and operator precedence with practical examples in C programming.

Uploaded by

kingjordi82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

Programming Concepts Answers

The document provides a comprehensive overview of programming concepts including compilers, variables, operators, loops, and error detection. It includes definitions, examples, and coding problems related to if-else statements, switch cases, and loops. Additionally, it covers naming conventions and operator precedence with practical examples in C programming.

Uploaded by

kingjordi82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Concepts – Full Answer Sheet

✅ Part - 1
1. Compiler, Operators, Operands, Expression

- Compiler: A compiler translates high-level code (like C or Java) into machine-level


language for execution.
- Operators: Symbols that perform operations. Example: +, -, *, /.
- Operands: Values/variables on which operators work. Example: In a + b, a and b are
operands.
- Expression: Combination of operators and operands that produces a result. Example: a + b
- c.

2. Variables, Constants, Type Casting (with Examples)

- Variable: A named memory location. Example: int age = 20;


- Constant: A fixed value. Example: const float PI = 3.14;
- Type Casting: Changing one data type into another. Example: float a = (float) 5 / 2; //
Output: 2.5

3. Tokens, Keywords, Format Specifiers

- Tokens: Smallest elements of a program (keywords, identifiers, constants, symbols).


- Keywords: Reserved words. Example: int, return, if, else.
- Format Specifiers:
%d → Integer
%f → Float
%c → Character
%s → String

✅ Part - 2
4. Variable Naming Convention (Valid & Invalid)

- Valid: studentName, marks_1, _total


- Invalid: 1name, class%, my name

5. Operators Definition and Example

- Arithmetic: +, -, *, /, %
- Relational: ==, !=, <, >, <=, >=
- Logical: &&, ||, !

6. Loop Definition
- For Loop: for(int i = 1; i <= 5; i++) { printf("%d ", i); }
- While Loop: int i = 1; while(i <= 5) { printf("%d ", i); i++; }
- Do-While Loop: int i = 1; do { printf("%d ", i); i++; } while(i <= 5);

7. If-Else Definition with Structure

int a = 10, b = 20;


if(a > b) {
printf("A is greater");
} else {
printf("B is greater");
}

8. Switch Case with Structure

int day = 3;
switch(day) {
case 1: printf("Monday"); break;
case 2: printf("Tuesday"); break;
case 3: printf("Wednesday"); break;
default: printf("Invalid Day");
}

9. Error Detection

- Syntax error: missing ;


- Undeclared variable: using a variable not defined
- Type mismatch: assigning float to int without casting

10. Operators Precedence (Show Output Step by Step)

int result = 5 + 2 * 3;
Multiplication first: 2 * 3 = 6
Then addition: 5 + 6 = 11
Output: 11

11. Naming Convention – Valid and Invalid Check

- Valid: age, roll_no, name123


- Invalid: 123name, student-name, total marks

✅ Code-Related Problems
1. If-Else (Greatest of 3 Numbers, Even or Odd)

int a = 5, b = 10, c = 7;
if(a > b && a > c)
printf("A is greatest");
else if(b > c)
printf("B is greatest");
else
printf("C is greatest");

// Even or Odd
int x = 9;
if(x % 2 == 0)
printf("Even");
else
printf("Odd");

2. Switch Case (Grading and Day)

int marks = 85;


switch(marks / 10) {
case 9: printf("Grade A"); break;
case 8: printf("Grade B"); break;
case 7: printf("Grade C"); break;
default: printf("Fail");
}

int day = 2;
switch(day) {
case 1: printf("Sunday"); break;
case 2: printf("Monday"); break;
case 3: printf("Tuesday"); break;
//...
}

3. Nested Loop (Pyramid Pattern)

for(int i = 1; i <= 5; i++) {


for(int j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}

4. Number Printing (for loop)

for(int i = 1; i <= 10; i++) {


printf("%d\n", i);
}

You might also like