K&R C Programs Exercise 5-1

Exercise 5-1. As written, getint treats a + or – not followed by a digit as a valid representation of zero. Fix getint so that it pushes such a character back on the input. K&R’s getint from Section 5.2 reads an optional sign then digits. The bug: if + or – appears but the next …

C Program: Array Summation Using Pointers

This program reads N integers into a dynamically allocated array and computes their sum using pointer arithmetic instead of array subscript notation. Understanding the equivalence between *(a + i) and a[i] is fundamental to C — both produce identical machine code. The program also demonstrates malloc() and free() for runtime-sized arrays. The original post used …