ACS101 · Programming Languages · Unit 1
Programming Basics (C)
Unit Scope & Exam Weightage: This unit is the foundation of C programming: structure of a C program, compilation and execution, data types/variables/constants, arithmetic, relational and logical operators, scanf/printf, type conversion and simple expressions. It carries 38 PYQ clusters worth 176 marks (20 × 7m and 18 × 2m) from
2023-24,2024-25and2025-26. Three clusters are marked Survival Mode; all three test operator behaviour, so precedence, associativity and implicit/explicit conversion are the first things to revise.
Front Page: Importance-Wise Topic Roadmap (2023–26 PYQs)
| Priority | Topic (Exact Syllabus) | PYQs Asked | Marks Weightage | Tag |
|---|---|---|---|---|
| 1 | operators (arithmetic, relational, logical) | 15 (2023-24 ×7, 2024-25 ×6, 2025-26 ×2) |
7m × 10 + 2m × 5 = 80m | Survival Mode High Yield |
| 2 | Data types / variables / constants | 7 (2023-24 ×4, 2024-25 ×2, 2025-26) |
7m × 4 + 2m × 3 = 34m | High Yield |
| 3 | Type conversion | 3 (2023-24 ×2, 2024-25) |
7m × 2 + 2m = 16m | Survival Mode Numerical |
| 4 | Structure of a C program | 2 (2024-25) |
7m × 2 = 14m | Theory + Code |
| 5 | compilation and execution | 2 (2024-25) |
7m + 2m = 9m | Theory |
| 6 | Input/output — scanf/printf in C | 2 (2024-25, 2023-24) |
2m × 2 = 4m | Quick Score |
| 7 | simple expressions Real connect: C powers embedded systems | 1 (2023-24, pattern/series program) |
7m | Program |
| 8 | microcontrollers | attached to #7 | — | Real Connect |
| 9 | and OS kernels | attached to #4 and #5 | — | Real Connect |
| 10 | Storage classes (attached PYQ topic) | 2 (2023-24) |
7m × 2 = 14m | Attached Extra |
| 11 | Macros and tokens (attached PYQ topics) | 4 (2023-24, 2024-25) |
2m × 3 + 7m = 13m | Attached Extra |
| 12 | Dynamic allocation malloc/calloc (attached PYQ topic) |
2 (2024-25, 2023-24) |
7m × 2 = 14m | Attached Extra |
2-Hour Last-Night Survival Checklist:
- Precedence ladder: memorise unary > arithmetic
* / %>+ -> relational > equality >&&>||> assignment > comma. Write it at the top of the answer sheet before any output question. - Macro trap:
#define a 22+2expands without parentheses;2/abecomes2/22+2 = 4, not2/6. This exact PYQ has appeared twice. - Conversion direction: implicit promotion follows
char → int → float → double; explicit casting is(float)a/b. State that integer division truncates before promotion is applied. - Storage classes one-liner:
auto= block/default,register= CPU hint,static= retains value across calls,extern= defined elsewhere. A table of four rows is a guaranteed 7-marker. - Two-minute codes: keep templates ready for natural numbers 10–100, conditional-operator max, and
scanf/printfpurpose. These recur as exact 2-mark questions.
1. Structure of a Basic C Program
C program skeleton: a C source file contains, in order, preprocessor directives (#include, #define), optional global declarations, function declarations/prototypes, main(), and user-defined function definitions. Every statement ends with a semicolon; blocks are enclosed in braces.
#include <stdio.h> /* preprocessor: header for scanf/printf */
#define MAX 100 /* macro substitution */
int add(int, int); /* prototype */
int main(void) { /* execution begins here */
int a = 5, b = 7, s;
s = add(a, b);
printf("Sum = %d\n", s);
return 0;
}
int add(int x, int y) { /* user-defined function */
return x + y;
}
| Part | Purpose | Exam keyword |
|---|---|---|
#include <stdio.h> |
Brings declarations of standard I/O functions | Preprocessor directive |
#define MAX 100 |
Textual replacement before compilation | Macro |
int add(int,int); |
Tells compiler the function signature before use | Prototype |
int main(void) |
Mandatory entry point; returns int status to OS |
Main function |
return 0; |
Signals successful execution | Exit status |
Examiner Tip: For “structure of a basic C program”, draw the five parts in the order shown and annotate one line of code for each. Marks are usually awarded per labelled part, not for a long prose introduction.
2. Compilation and Execution
Object file: a machine-code translation of one source file produced by the compiler, containing relocatable code and a symbol table but not yet linked to library functions. It is saved as .obj (Windows) or .o (GCC/Unix).
%%{init: {'theme': 'base', 'look': 'handDrawn', 'themeVariables': {'fontFamily': "'Nunito', sans-serif", 'fontSize': '17px', 'primaryColor': '#EFEAD6', 'primaryBorderColor': '#0F766E', 'lineColor': '#23211C'}}}%%
flowchart LR
A["hello.c<br/>source file"] --> B["Preprocessor<br/>expands #include and #define"]
B --> C["Compiler<br/>hello.s / hello.o"]
C --> D["Linker<br/>adds stdio library"]
D --> E["a.out / hello.exe<br/>executable"]
E --> F["Loader loads into RAM"]
F --> G["CPU executes main()"]
| Stage | Tool | Input → Output | What it checks |
|---|---|---|---|
| Preprocessing | cpp |
.c → expanded .c |
Macros, headers, conditional compilation |
| Compilation | gcc -c |
expanded .c → .o |
Syntax, semantic types, optimisation |
| Linking | gcc |
.o + libraries → executable |
Resolves printf, scanf, user functions |
| Loading | OS loader | executable → main memory | Allocates stack, heap, code segment |
| Execution | CPU | machine instructions | Runs main() until return |
Compiler vs interpreter (2-mark PYQ): a compiler translates the whole program to machine code before execution and reports all errors up front, producing a standalone object/executable. An interpreter translates and executes line by line, has no separate object file, and stops at the first error. C uses a compiler; Python commonly uses bytecode plus an interpreter.
3. Data Types, Variables and Constants
Variable: a named memory location whose value can change during execution. Constant: a fixed value that cannot be modified; written with const or as a literal. Token: the smallest meaningful unit of a C program—keyword, identifier, constant, string literal, operator or punctuation.
| Data type | Typical GCC 32-bit size | Range | Format specifier |
|---|---|---|---|
char |
1 byte | −128 to 127 (signed) | %c |
int |
4 bytes | −2,147,483,648 to 2,147,483,647 | %d |
float |
4 bytes | ≈ 3.4 × 10³⁸, 6 digits precision | %f |
double |
8 bytes | ≈ 1.7 × 10³⁰⁸, 15 digits | %lf |
void |
no value | — | — |
unsigned int |
4 bytes | 0 to 4,294,967,295 | %u |
User-defined data types: struct (groups mixed members), union (members share one memory location), enum (named integer constants), and typedef (new name for an existing type). Derived types include arrays and pointers.
One nibble = 4 bits = 0.5 byte. This is the answer to the 2023-24 one-line question; a byte is 8 bits, so two nibbles make one byte.
const float PI = 3.14159f; /* constant: value cannot be assigned again */
int marks = 85; /* variable: name + type + initial value */
char grade = 'A'; /* character constant in single quotes */
Examiner Tip: If a question asks “range, format specifier, memory size”, present a four-column table. State the compiler assumption (“GCC 32-bit”) because old Turbo C uses a 2-byte int; stating the assumption prevents a marking dispute.
4. Operators: Arithmetic, Relational, Logical and More
Associativity: unary, conditional and assignment operators are right-to-left; all others are left-to-right.
| Category | Operators | Example | Result |
|---|---|---|---|
| Arithmetic | + - * / % ++ -- |
17 % 5 |
2 |
| Relational | < <= > >= == != |
5 == 5 |
1 (true) |
| Logical | && || ! |
(3>2) && (5<4) |
0 |
| Bitwise | & | ^ << >> ~ |
6 & 3 |
2 (110 & 011) |
| Assignment | = += -= *= /= %= |
x += 3 |
same as x = x+3 |
| Conditional | ?: |
(a>b)?a:b |
larger of a,b |
| Comma | , |
for(i=0,j=1; ...) |
evaluates left to right |
Operator vs operand: an operator is the symbol that specifies an operation (+), while an operand is the value on which it acts (a and b in a+b). In 2/a, / is the operator and 2, a are operands.
Worked precedence trace: int x = 8/4*2 + 1; → 8/4 = 2, 2*2 = 4, 4+1 = 5, so x = 5. A common error is to multiply 4*2 first; division and multiplication have equal precedence and associate left-to-right.
Logical vs bitwise: && evaluates the whole right operand only when needed and returns 0/1; & always evaluates both operands and works bit by bit. For a=6, b=3, a && b is 1 but a & b is 2.
5. Input/Output: scanf() and printf()
printf() writes formatted output to standard output; scanf() reads formatted input from standard input. Both are declared in <stdio.h>. The format string controls conversion; the ampersand & in scanf supplies the address of the destination variable.
#include <stdio.h>
int main(void) {
int age;
float salary;
printf("Enter age and salary: ");
scanf("%d %f", &age, &salary); /* & is essential for scalars */
printf("Age = %d, Salary = %.2f\n", age, salary);
return 0;
}
%d reads a decimal integer, %f reads a float, %lf reads a double with scanf, %c reads one character, and %s reads a string (up to whitespace). Omitting & in scanf("%d", age) passes an uninitialised value as an address and causes undefined behaviour—an examiner favourite in debugging questions.
6. Type Conversion and Casting
Implicit conversion (coercion) is automatic promotion of a lower-rank type to a higher-rank type in a mixed expression: char → short → int → long → float → double. Explicit conversion (casting) is programmer-directed: (cast_type)expression.
| Case | Expression | Value | Why |
|---|---|---|---|
| Integer division | 7/2 |
3 |
Both operands are int; truncation |
| Implicit promotion | 7/2.0 |
3.5 |
2.0 is double, so 7 promoted |
| Explicit cast | (float)7/2 |
3.5 |
Cast applied before division |
| Assign-back narrowing | int x = 7/2.0; |
3 |
Result truncated on assignment |
#include <stdio.h>
int main(void) {
int a = 7, b = 2;
printf("implicit-free int division = %d\n", a/b); /* 3 */
printf("promoted = %.2f\n", a/(float)b); /* 3.50 */
printf("explicit = %.2f\n", (float)a/b); /* 3.50 */
return 0;
}
Examiner Tip: In a 7-mark type-casting answer, show the conversion before the arithmetic. Writing (float)(a/b) gives 3.0, not 3.5, and examiners specifically test this placement of parentheses.
7. Simple Expressions and the Embedded/Kernel Real Connect
A C expression combines operators and operands and always yields a value. Expressions are the working language of low-level code because they map closely to machine instructions:
| Domain | Typical C expression | Meaning |
|---|---|---|
| Microcontrollers | PORTB |= (1 << PB3); |
Set bit 3 of an I/O register without disturbing other pins |
| Embedded sensor | raw = (adc << 2) | 0x03; |
Shift a 10-bit ADC reading and append status bits |
| OS kernel | flags &= ~MASK; |
Clear selected flag bits atomically in one statement |
| Kernel scheduling | if (ticks-- == 0) resched(); |
Decrement a counter and request rescheduling at zero |
These are genuine uses of the unit's arithmetic/bitwise operators; they are not separate theory topics.
8. Attached PYQ Topics: Tokens, Macros and Storage Classes
Tokens: keyword (int, if), identifier (marks), constant (100), string literal ("Hi"), operator (+), punctuation (;, {}). The compiler's lexical analyser groups characters into tokens before parsing.
Macros: #define NAME replacement is processed by the preprocessor; there is no type checking and no semicolon in the definition. Parenthesise every argument in macro bodies: #define SQUARE(x) ((x)*(x)), otherwise SQUARE(a+1) expands to a+1*a+1.
| Storage class | Lifetime | Scope | Default initial value | Keyword |
|---|---|---|---|---|
| Automatic | Block entry to exit | Block | Indeterminate garbage | auto |
| Register | Block entry to exit | Block | Indeterminate; stored in CPU register if possible | register |
| Static | Whole program run | Defining block/file | Zero | static |
| External | Whole program run | Whole program via extern |
Zero | extern |
9. Solved Exam-Ready Questions (Exact PYQ Wording)
Solved Q1 (2023-24, 2025-26, 7 Marks | Survival Mode)
Q: What do you mean by operator precedence and associativity in C? Explain with suitable example.
Solution:
- Precedence decides which operator is applied first when several appear in one expression. Associativity decides the order when operators of the same precedence appear together.
- In
int x = 8/4*2;,/and*have equal precedence and associate left-to-right:8/4 = 2, then2*2 = 4. Hencex = 4. - In
int y = 2 + 3 * 4;,*has higher precedence than+:3*4 = 12,2+12 = 14. Hencey = 14. - Assignment is right-to-left:
a = b = 5;assigns5tobfirst and then toa. - Answer: precedence is the ranking of operators; associativity is the left/right grouping rule at equal rank.
Solved Q2 (2023-24, 2025-26, 2 Marks | Survival Mode)
Q: Differentiate between implicit and explicit type conversion in C.
Solution:
- Implicit: automatic compiler promotion in mixed expressions, e.g.
7 + 2.5promotes7to7.0and gives9.5(typedouble). No programmer action. - Explicit: programmer writes a cast, e.g.
(float)7/2gives3.5because the cast changes7to7.0before division. - Implicit follows the rank ladder
char → int → float → double; explicit can also narrow ((int)3.9gives3).
Solved Q3 (2024-25, 7 Marks | Survival Mode)
Q: Discuss the various operators used in the C programming language with examples.
Solution: The categories and examples are:
| Category | Symbols | Example | Value |
|---|---|---|---|
| Arithmetic | + - * / % |
9%4 |
1 |
| Relational | < <= > >= |
5>=5 |
1 |
| Equality | == != |
5!=4 |
1 |
| Logical | && || ! |
!0 |
1 |
| Bitwise | & | ^ ~ << >> |
1<<3 |
8 |
| Assignment | = += -= *= /= %= |
x=2; x*=3; |
6 |
| Increment/decrement | ++ -- |
i=1; ++i; |
2 |
| Conditional | ?: |
(2>1)?10:20 |
10 |
| Comma | , |
x=1,y=2 |
2 |
Also mention unary sizeof (sizeof(int) is typically 4) and address operators & and * used with pointers.
Solved Q4 (2023-24, 7 Marks)
Q: (i) Write a program in C language to print the following pattern: - 1 4 9 16 25 36 49 64 81 100 (ii) Write a program in C language to print the sum of following series: .
Solution:
#include <stdio.h>
int main(void) {
int i, n, x;
long long fact = 1, sum = 0;
/* (i) squares 1^2 to 10^2 */
for (i = 1; i <= 10; i++)
printf("%d ", i*i);
printf("\n");
/* (ii) sum = 1!/n! + 2!/n! + ... + x!/n! */
printf("Enter n and x: ");
scanf("%d %d", &n, &x);
for (i = 1; i <= n; i++) fact *= i; /* n! */
for (i = 1; i <= x; i++) {
long long f = 1;
int k;
for (k = 1; k <= i; k++) f *= k; /* i! */
sum += f / fact; /* integer terms */
}
printf("Sum = %lld\n", sum);
return 0;
}
The pattern is simply i*i for i = 1..10. For the series, compute n! once in fact, compute each i! in the inner loop, and accumulate i!/n!. If fractional terms are intended, use double sum and sum += (double)f/fact.
Solved Q5 (2024-25, 7 Marks)
Q: Discuss different types of operators in C with examples.
Solution: Same taxonomy as Solved Q3. For a 7-mark answer, add one essential distinction per category: / on integers truncates but % works only on integers; && and || short-circuit but & and | do not; ++i increments before use while i++ uses the old value first; == compares while = assigns.
int a = 6, b = 3;
printf("%d %d\n", a && b, a & b); /* 1 and 2 */
Solved Q6 (2024-25, 7 Marks)
Q: Explain the use of logical and bitwise operators with examples.
Solution:
- Logical:
&&is true only if both operands are non-zero;||is true if either is non-zero;!reverses truth. Example:if (age >= 18 && marks > 40)admits a candidate only when both hold. - Bitwise: operate on individual bits. For
a=6 (110),b=3 (011):a&b = 2 (010),a|b = 7 (111),a^b = 5 (101),~a = ...11111001,a<<1 = 12,a>>1 = 3. - Short-circuit trace: in
(x != 0) && (10/x > 2), the division is skipped whenx == 0; using&instead would cause division by zero.
Solved Q7 (2023-24, 7 Marks)
Q: Write a program in C language to calculate energy bill. Read the starting and ending meter readings. The charges are as follows:- 0 < units <= 200: Rs 5.50 per Unit 200 < units <= 400: Rs 700 + Rs 6.0 per unit excess of 200 400 < units <= 600: Rs 1400 + Rs 7.50 per unit excess of 400 600 < units: Rs 1850 + Rs 9.0 per Unit excess of 600
Solution:
#include <stdio.h>
int main(void) {
int start, end, units;
float bill;
printf("Enter starting and ending readings: ");
scanf("%d %d", &start, &end);
units = end - start;
if (units <= 0) { printf("Invalid reading\n"); return 0; }
if (units <= 200) bill = 5.50f * units;
else if (units <= 400) bill = 700 + 6.00f * (units - 200);
else if (units <= 600) bill = 1400 + 7.50f * (units - 400);
else bill = 1850 + 9.00f * (units - 600);
printf("Units = %d, Bill = Rs %.2f\n", units, bill);
return 0;
}
Check: at units = 200, slab 1 gives 1100 and slab 2 gives 700+6*0 = 700; the table is discontinuous, so follow the printed rates exactly rather than forcing continuity. At units = 350, bill = 700 + 6*150 = Rs 1600.
Solved Q8 (2024-25, 2 Marks)
Q: What are logical operators?
Solution: Logical operators combine relational expressions and return 1 (true) or 0 (false): && (AND), || (OR), ! (NOT). Example: (x > 0) && (x < 10) is true only for x = 1..9. They evaluate left to right and short-circuit.
Solved Q9 (2024-25, 2 Marks)
Q: Define Tokens and its use in Programming language.
Solution: A token is the smallest meaningful lexical unit recognised by a compiler—keyword, identifier, literal, operator or punctuation. Tokens are the input to the parser; for example int total = 10; tokenises as int, total, =, 10, ;. They make syntax checking possible.
Solved Q10 (2024-25, 2 Marks)
Q: What is operator precedence? Give an example.
Solution: Precedence is the priority order that decides which operator binds first in an expression without parentheses. Example: in 2 + 3 * 4, * binds before +, giving 14, not 20. Parentheses override precedence: (2+3)*4 = 20.
Solved Q11 (2024-25, 2 Marks)
Q: Define Macros and its use in C Programming.
Solution: A macro is a name replaced by a text string before compilation, defined with #define. Example: #define PI 3.14159 lets 2*PI*r become 2*3.14159*r. Macros avoid repeated constants and enable conditional compilation; they have no type checking, so parenthesise macro bodies.
Solved Q12 (2023-24, 2 Marks)
Q: Find the value of variable max in the following code: - int a=10, b=20; int max=(a>b)? a: b;
Solution: a > b is 10 > 20, which is false (0). The conditional operator therefore selects the third operand b. Answer: max = 20.
Solved Q13 (2023-24, 2 Marks)
Q: Differentiate Between Operator and Operands.
Solution: An operator specifies the operation to be performed (+, -, *, /, ==); an operand is the data item on which the operator acts. In c = a + b, + is the operator and a, b are operands; = is also an operator with c and (a+b) as operands.
Solved Q14 (2023-24, 2 Marks)
Q: Define Conditional Operator with an example.
Solution: The conditional operator ?: is the only ternary C operator: condition ? expr1 : expr2. It returns expr1 when the condition is non-zero, otherwise expr2. Example: int max = (a > b) ? a : b; stores the larger value.
Solved Q15 (2023-24, 2 Marks)
Q: Find the output of following code: - #include<stdio.h> #define a 2*2+2 void main () { int b,c; b=2/a; c=b+4; printf("Value of variable b and c are %d%d respectively ", b,c); }
Solution:
- Macro expansion is textual:
a→2*2+2. b = 2/a;becomesb = 2/2*2+2;./and*have equal precedence and associate left-to-right:2/2 = 1,1*2 = 2,2+2 = 4. Henceb = 4.c = b + 4 = 8.%d%dwith no separating space prints48.- Output:
Value of variable b and c are 48 respectively.
Solved Q16 (2023-24, 7 Marks)
Q: Explain the Storage Classes used for the storage of the Data in C programming.
Solution: The four storage classes are auto, register, static and extern, summarised in Section 8. Key points: auto and register have block scope and block lifetime; register requests a CPU register (address cannot be taken); static preserves its value between function calls and is zero-initialised; extern declares a variable/function defined in another translation unit. Example: a static int count inside a function keeps incrementing across calls, while auto int count resets each call.
Solved Q17 (2023-24, 7 Marks)
Q: Write the Short notes on (i) Linked list (ii) macros.
Solution:
(i) Linked list: a linear collection of nodes, each containing data and a pointer to the next node. Unlike an array, nodes need not be contiguous and can grow at runtime. Head pointer gives access; insertion at head is new->next = head; head = new;. Used where frequent insertion/deletion is needed.
(ii) Macros: #define substitutions processed before compilation, with object-like (#define MAX 100) and function-like (#define SQUARE(x) ((x)*(x))) forms. Advantages: faster than function calls for tiny expressions and no type restriction; limitations: no type checking and repeated evaluation of arguments.
Solved Q18 (2023-24, 7 Marks)
Q: What is the different user defined data types in C language? Write range, Format specifier, memory size of primitive data types.
Solution: User-defined types: struct, union, enum, and names created by typedef. Primitive data types (GCC 32-bit assumption) are given in the Section 3 table: char 1 byte %c −128…127; int 4 bytes %d −2,147,483,648…2,147,483,647; float 4 bytes %f ≈3.4×10³⁸; double 8 bytes %lf ≈1.7×10³⁰⁸. State that unsigned doubles the upper bound and starts at zero.
Solved Q19 (2024-25, 7 Marks)
Q: Write and explain the structure of a basic C program.
Solution: Use the code and five-part table in Section 1. Explain: preprocessor directives are handled before compilation; prototypes allow calls before definitions; main() is the entry point; declarations allocate typed storage; executable statements perform work; return 0; reports success to the operating system.
Solved Q20 (2024-25, 7 Marks)
Q: Define Obj file. Discuss the Compilation process step by step in C Programming.
Solution: An object file is the relocatable machine code produced by gcc -c prog.c (prog.o). It contains translated instructions, data and a symbol table, with unresolved calls such as printf. The steps are preprocessing → compilation (.o) → linking with libraries → loading into memory → execution of main(), as shown in the Section 2 diagram. The linker resolves printf from libc; the loader sets up the stack and heap before the CPU starts.
Solved Q21 (2023-24, 7 Marks)
Q: Discuss the Concept of Type Casting and Type Conversion with the Program.
Solution: Use the Section 6 program. Emphasise: implicit promotion happens automatically and follows rank order; explicit cast (float)a/b converts a before division. Show the contrast (float)(a/b) = 3.0 versus (float)a/b = 3.5 for a=7,b=2; the placement of the cast is the tested point.
Solved Q22 (2024-25, 2 Marks)
Q: Explain the purpose of the and functions in C.
Solution: printf() sends formatted text from memory to standard output using conversion specifications such as %d, %f, %c; scanf() reads formatted text from standard input and stores converted values at the addresses given by &variable. Both are declared in stdio.h.
Solved Q23 (2023-24, 2 Marks)
Q: Write a C program to print all natural numbers from 10 to 100.
Solution:
#include <stdio.h>
int main(void) {
int i;
for (i = 10; i <= 100; i++) printf("%d ", i);
return 0;
}
The loop initialiser is 10, the test is <= 100, and i++ advances by one.
Solved Q24 (2023-24, 7 Marks)
Q: Define Algorithm. Write the Algorithm for the greatest of three numbers and Draw its flow chart.
Solution: An algorithm is a finite, ordered sequence of unambiguous steps that terminates with a result.
Algorithm:
- Read
a, b, c. - If
a > bgo to step 3, else go to step 4. - If
a > csetmax = a, elsemax = c; go to step 7. - If
b > csetmax = b, elsemax = c. - Print
max. - Stop.
%%{init: {'theme': 'base', 'look': 'handDrawn', 'themeVariables': {'fontFamily': "'Nunito', sans-serif", 'fontSize': '17px', 'primaryColor': '#EFEAD6', 'primaryBorderColor': '#0F766E', 'lineColor': '#23211C'}}}%%
flowchart TD
A[Start] --> B[Read a, b, c]
B --> C{a > b?}
C -->|yes| D{a > c?}
C -->|no| E{b > c?}
D -->|yes| F[max = a]
D -->|no| G[max = c]
E -->|yes| H[max = b]
E -->|no| G
F --> I[Print max]
G --> I
H --> I
I --> J[Stop]
10. Practice Questions (Self-Test)
- (2 Marks) Write the output:
int a=3; printf("%d %d", a++, ++a);withastarting at 3. (Hint: evaluate arguments right-to-left under GCC; be ready to justify either order.) - (7 Marks) Write a C program to read three numbers and print the largest using the conditional operator only.
- (7 Marks) Explain with code why
(float)(7/2)differs from(float)7/2. - (7 Marks) Write a program using a
staticcounter to show that its value survives between two function calls. - (2 Marks) State one difference between a compiler and an interpreter and name the file produced by
gcc -c.