BSEB Inter Computer Science study materials
BSEB Inter Computer Science study resources

BSEB Inter Computer Science: Programming in C

BSEB Inter Computer Science · Work through your exam, one topic at a time.

All guide sections

Programming in C

Programming in C tests the structure of a C program, data types, operators, control structures, functions, arrays, pointers, strings and file handling.

Core rules

A C program contains preprocessor directives, function definitions and statements. Execution begins at main(). Standard headers include stdio.h, conio.h, math.h and string.h. Data types include int, float, double, char and void, with qualifiers such as short, long, signed and unsigned. Operators include arithmetic, relational, logical, bitwise, assignment and conditional. Control structures are sequence, selection (if, if–else, switch) and iteration (for, while, do–while). Functions have a return type, name, parameter list and body; call by value copies arguments, while call by reference passes addresses. Arrays are zero-indexed. A string is a char array ending in '\0'. Pointers store addresses. File handling uses fopen(), fclose(), fprintf(), fscanf(), fgetc() and fputc(); modes include 'r', 'w', 'a', 'rb' and 'wb'.

Worked example

int a[5] = {10, 20, 30, 40, 50}; int *p = a; printf("%d", *(p + 2)); The array name decays to the address of a[0]. p + 2 points to a[2], and *(p + 2) gives 30. The pointer moves in units of the pointed-to type, not bytes.

Traps

= assigns, == compares. Array indices run from 0 to n−1. scanf() needs addresses for basic variables. A string needs space for the null terminator. fopen() returns NULL on failure; check it before reading. do–while executes at least once.