C Aptitude Questions and answers with explanation

C Aptitude 29C program is one of most popular programming language which is used for core level of coding across the board. C program is used for operating systems, embedded systems, system engineering, word processors,hard ware drivers, etc. In this site, we have discussed various type of C programs till date and from now on, …

K&R C Chapter 5 Exercise Solutions — Pointers and Arrays

Chapter 5: Pointers and Arrays is the chapter C beginners fear most — and with reason. K&R covers pointer arithmetic, the equivalence between pointers and arrays, pointers to functions, and multi-dimensional arrays. The exercises build real utilities: getfloat, strncpy/strncat/strncmp from scratch, a tail command, a sort program with -r/-n/-f/-d flags, and a full C declaration …

K&R C Programs Exercise 7-4

Exercise 7-4. Write a private version of scanf analogous to the private printf described in this section. Like minprintf, minscanf parses a format string and uses va_list to accept a variable number of pointer arguments. It reads from stdin and dispatches to the appropriate conversion — using scanf itself with a constructed sub-format string, so …

K&R C Programs Exercise 5-20

Exercise 5-20. Expand dcl to handle declarations with function argument types, qualifiers like const, and so on. The basic dcl treats () as “function returning” but ignores argument types. This exercise adds: parameter lists inside (), type qualifiers (const, volatile), storage classes (static, extern), and the void type. The approach: when ( is encountered and …

K&R C Programs Exercise 5-17

Exercise 5-17. Add a field-handling capability, so sorting may be done on fields within lines, each field sorted according to an independent set of options. (The index for this book was sorted with -df for the index category and -n for the page numbers.) Fields are whitespace-delimited columns. The syntax -k<field>[flags] selects a 1-based field …

K&R C Programs Exercise 5-15

Exercise 5-15. Add the option -f to fold upper and lower case together, so that case distinctions are not made during sorting; for example, a and A compare equal. Add a fold flag. When set, the comparison function converts both characters to lowercase before comparing. The key: don’t modify the strings themselves — do the …