Questions tagged [kr-c]

For questions about K&R C, the pre-standard language described in the first edition of "The C Programming Language" by Kernighan & Ritchie

This tag is for questions about the pre-standard C language as defined by the first version of "The C Programming Language" by Brian Kernighan and Dennis Ritchie, published in 1978.

The second edition of the book was published shortly before ratification of the first standard in 1990 and describes that version of the language (C90).

For questions about the book, use instead.

36 questions
50
votes
3 answers

Function declaration: K&R vs ANSI

What are the differences between a K&R function declaration and an ANSI function declaration?
ashna
  • 7,159
  • 4
  • 20
  • 9
48
votes
11 answers

What are the major differences between ANSI C and K&R C?

The Wikipedia article on ANSI C says: One of the aims of the ANSI C standardization process was to produce a superset of K&R C (the first published standard), incorporating many of the unofficial features subsequently introduced. However, the…
Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
40
votes
6 answers

What's a good example of register variable usage in C?

I'm reading through K&R and came to the small section on register variables, and was wondering if people here have some good examples of this put into practice. From section 4.7 in K&R: The register declaration looks like register int x; …
Kyle Walsh
  • 2,774
  • 4
  • 27
  • 25
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
10
votes
4 answers

K&R Chapter 1 - Exercise 22 solution, what do you think?

I'm learning C from the k&r as a first language, and I just wanted to ask, if you thought this exercise was being solved the right way, I'm aware that it's probably not as complete as you'd like, but I wanted views, so I'd know I'm learning C…
svr
10
votes
4 answers

correctly declaring the main() function in ANSI C

The C standard say: The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters: int main(void) { /* ... */ } or…
zaharpopov
  • 16,882
  • 23
  • 75
  • 93
9
votes
11 answers

How did C look like before I was born?

Here is the question, How did C (K&R C) look like? The question is about the first ten or twenty years of C's life? I know, well I heard them from a prof in my uni, that C didn't have the standard libraries that we get with ANSI C today. They used…
Khaled Alshaya
  • 94,250
  • 39
  • 176
  • 234
8
votes
6 answers

K&R C Exercise Help

I've been going through the K&R C Programming Language book and I'm stuck on Exercise 2-6 which reads: Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other…
Koby
  • 7,267
  • 2
  • 21
  • 16
8
votes
5 answers

K&R Qsort example with Pointers and Arrays confusion

I find it difficult to understand the following snippet of code. I understand the pointer to function mannerism showed, but where I find confusion is in the indicated lines. void qsort(void **v, int left, int right, int (*comp) (void *, void *)) { …
radd
7
votes
5 answers

Problem with example 1.5.2 in K&R book on C

I'm teaching myself C with K&R and am stumped by one of the examples in the book. I compile the code exactly as it is written in the example but it does not do what the authors say it will. The program is supposed to count characters. The code…
Dan
  • 73
  • 1
  • 3
6
votes
8 answers

K&R Exercise 1-21 - Mental incomprehension

The "impossible" K&R exercise. "Write a program entab that replaces strings of blanks by the minimum number of tabs and blanks to achieve the same spacing. Use the same tab stops, say every n columns. Should n be a variable or a…
asdfg
  • 61
  • 1
  • 2
6
votes
2 answers

How to convert from K&R C to ANSI C?

I am trying to execute following code which is the 1988 entry of Obfuscated C Code Contest. #define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ …
Vadakkumpadath
  • 1,445
  • 13
  • 21
5
votes
3 answers

pointer to array of integers and normal array of integers

In KR C book page 112 it says that following: int (*arr1)[10]; is a pointer to an array of 10 integers. I don't get what's difference between above and: int arr2[10]; 1- Isn't arr2 itself a pointer to array of 10 integers? (Because name of an…
doubleE
  • 1,027
  • 1
  • 12
  • 32
5
votes
3 answers

k&r exercise confusion with bit-operations

The exercise is: Write a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged. My attempt at a solution is: #include unsigned…
svr
  • 51
  • 2
1
2 3