Questions tagged [kernighan-and-ritchie]

Questions about or related to the book "The C Programming Language" (which is also known as K&R) by Brian Kernighan and Dennis Ritchie.

Questions about or related to the book "The C Programming Language" (which is also known as K&R) by Brian Kernighan and Dennis Ritchie.

The authors came together to write the book in conjunction with the language's early development at AT&T Bell Labs.

There have been two editions of the book. The first edition, commonly called "K&R1", was published in 1978 and describes a pre-standard version of the language. This edition is now mostly of historical interest.

The second edition, "K&R2", was first published in 1988 with some updates of the book to meet the version of the language standardized by ANSI in 1989.

(The 1989 ANSI C standard was republished by ISO in 1990 and a normative amendment was released in 1995. New versions of the standard were published in 1999 and 2011. There have been no new editions of K&R covering any of the changes to the language since 1990.)

335 questions
18
votes
5 answers

(K&R) At least the first 31 characters of an internal name are significant?

When taken literally, it makes sense, but what exactly does it mean to be a significant character of a variable name? I'm a beginning learner of C using K&R. Here's a direct quote from the book: "At least the first 31 characters of an internal name…
withchemicals
  • 357
  • 3
  • 8
16
votes
2 answers

In a function call, what is the operator, and what are the operands?

I am trying to understand some basics of C. KRC's The C Programming Language says A function call is a postfix expression, called the function designator, followed by parentheses containing a possibly empty, comma-separated list of …
Tim
  • 1
  • 141
  • 372
  • 590
12
votes
2 answers

K&R Exercise 1-20 - Need some clarification

I don't fully understand what the following exercise is asking: "Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. Assume a fixed set of tab stops, say every n columns. Should n be…
user731914
12
votes
6 answers

Should I do all the exercises in K&R?

This is a quick slightly subjective question I need to ask. In order to become a proficient C programmer, I felt I'd learn C from the k&r. I find the book a little easygoing, difficult to understand sometimes but easygoing on the whole. My…
servicer
12
votes
4 answers

What is the purpose of ungetc (or ungetch from K&R)?

Can anyone explain to me the purpose of ungetch? This is from K&R chapter 4 where you create a Reverse Polish Calculator. I've ran the program without the call to ungetch and in my tests it still works the same. int getch(void) /* get a (possibly…
Tyler
  • 4,679
  • 12
  • 41
  • 60
12
votes
10 answers

How exactly are data types represented in a computer?

I'm a beginning programmer reading K&R, and I feel as if the book assumes a lot of previous knowledge. One aspect that confuses me is the actual representation, or should I say existence, of variables in memory. What exactly does a data type specify…
withchemicals
  • 357
  • 3
  • 8
11
votes
4 answers

How to not invoke warning: type specifier missing?

I am reading "The C programming Language" by Brian W. Kernighan and Dennis M. Ritchie. In chapter 1.2 "Variables and Arithmetic Expressions" they demonstrate a simple Fahrenheit to Celsius converter program. When I compile the program (Terminal.app,…
MmmHmm
  • 3,435
  • 2
  • 27
  • 49
8
votes
3 answers

How to determine the ranges of floating-point types using direct computation?

I'm trying to solve exercise 2-1 from "The C Programming Language", 2nd edition, which asks to: "Write a program to determine the ranges of char, short, int, and long variables, both signed and unsigned, by printing appropriate values from standard…
user731914
8
votes
2 answers

Confusion with implementation of malloc from K&R

I've been reading through K&R and encountered a point of confusion in the implementation of malloc() included. typedef long Align; /* for alignment to long boundary */ union header { /* block header */ struct { union header *ptr; /* next…
screeb
  • 625
  • 6
  • 20
8
votes
1 answer

bit count function in K&R

In the book "C Programming Language" by K&R, there is a bit count function: int bitsCount(unsigned x) { int b; for (b = 0; x != 0; x >>= 1) if (x & 01) b++; return b; } My question is why they use x & 01 but not x &…
wuyefeibao
  • 237
  • 1
  • 9
8
votes
6 answers

argv pointer to an array of pointers

I am confused as to how the following passage matches up with the code that follows it: Since argv is a pointer to an array of pointers, we can manipulate the pointer rather than index the array. This next variant is based on incrementing argv,…
ericgrosse
  • 1,490
  • 20
  • 37
8
votes
9 answers

K & R Exercise: My Code Works, But Feels Stinky; Advice for Cleanup?

I'm working on the K&R book. I've read farther ahead than I've done exercises, mostly for lack of time. I'm catching up, and have done almost all the exercises from chapter 1, which is the tutorial. My issue was exercise 1-18. The exercise is…
John Rudy
  • 37,282
  • 14
  • 64
  • 100
7
votes
3 answers

How exactly is this function an example of a char to int conversion?

The book The C Programming Language by Kernighan and Ritchie, second edition states on page 43 in the chapter about Type Conversions: Another example of char to int conversion is the function lower, which maps a single character to lower case for…
efie
  • 544
  • 5
  • 22
7
votes
6 answers

C Programming Exercise from the K&R Book

Any idea why the following code doesn't print the amount of characters in the input? I've taken this straight from the K&R book. Learning C at the moment and this is really confusing, looks to me like I'm never reaching EOF. If that's the case then…
john
7
votes
3 answers

Ansi C - programming language book of K&R - header file inclusion

Going through the K&R ansi C programming language book (second version), on page 82 an example is given for a programming files/folders layout. What I don't understand is, while calc.h gets included in main (use of functions), getop.c (definition…
hewi
  • 1,274
  • 3
  • 17
  • 32
1
2
3
22 23