Be Confused to Solve Confusion.


The solution shall arrive...

C FAQ

 

 

 

You may search this page:  

 

 

 

C FAQs

C FAQ has now moved to http://faq.zanvar.in

(This page will continue to exist)

 

Of late, my newsgroup activities have increased. I am a member of comp.lang.c, Uttara and C_Spice groups. Following are few links to questions which I found useful in enrichment of my knowledge.

This page had been once reviewed by comp.lang.c. Of course, I will keep updating this page. HTML version of this page is available.

I have documented my learning of Pointers and Arrays.

You may ask me questions.

I write for OpenAsthra.

 

 

Programmers Heaven - Where programmers go!has provided a link to this page.  Click here, and look for the title, Advanced C Questions.

 

 

 


 

Dennis M. Ritchie answers my Just One Question!
The reason to write him was this!

 


 

 

C Questions

 

1.

What is Bus Error? Answer 1.

 

2.

What is Bus Error? Answer 2.

 

3.

What is Bus Error? Answer 3.

 

4.

What is Bus Error? Answer 4.

 

5.

Does any one know how to convert a multi byte char to unsigned long? Answer.

 

 

 

 

6.

What is trigraph and `entry' keyword? Answer.

 

7.

Can we attempt to write garbage collection in C? Answer.

 

8.

A tip for writing conditional statements. Tip.

 

9.

Know about IEEE 754, floating point format. (This is not C) Answer.

 

10.

K&R C vs. ANSI C Answer.

 

 

 

 

11.

Know about storage of local static variables... Answer. (gcc specific)

 

12.

What is memory leak? Answer. (UNIX specific)

 

13.

I have a good tutorial on pointers written by Ted Jensen. Tutorial.

 

14.

How do you rate yourself in C? Answer.

 

15.

How to specify width and precision in printf dynamically? Answer.

 


 

 

 

 

16.

How to decipher a pointer declaration? Answer.

 

17.

Can I find the sizeof a function? Answer Answer.

 

18.

Why can't I increment an array like a pointer? Answer.

 

19.

How to distinguish parameter passing techniques? Answer .

 

20.

How to allocate a 2 dimensional array dynamically? Answer. Picture. (See Q. 41)

 

 

 

 

21.

Printing 1 to 100 and 100 to 1 without using loops. Answer.

 

22.

An analysis of a C program involving pointers. Read.

 

23.

Case conversion without using arithmetic op. or library functions. Program. (ASCII specific)

 

24.

Program to compare two structures. Program.

 

25.

An obfuscated C program analysis Read.

 

 

 

 

26.

About: Union. Read.

 

27.

About: Array access vs. Pointer access. Read.

 

28.

About: Cast operation. Read.

 

29.

About: sizeof operator and size_t Read.

 

30.

About: #pragma usage Read.  (See Q. 104)

 

 

 

 

31.

About: Stream buffering Answer.

 

32.

About: Bit-fields. Read.

 

33.

Why multiplication of pointers is not allowed? Answer.

 

34.

Implementation of sizeof operator. Answer. (see question 84)

 

35.

Why this program does not work? (Pointer arithmetic) Answer.

 

 

 

 

36.

Counting the number of bits set to 1 in a float Read.

 

37.

Delete an arbitrary node from a singly linked-list. Solution.

 

38.

Reverse a singly linked-list with the given condition. Solution.

 

39.

Macro to find the maximum of 4 integers. Solution.

 

40.

Program to add/subtract two integers without using + or - . Program.

 

 

 

 

41.

How to allocate a 3 dimensional array dynamically? Answer. (See Q. 20)

 

42.

C code analysis (programming style). Read.

 

  

 

 

 


On February 6, 2004, I posted this FAQ page to comp.lang.c for reviewing. The above 42 questions were reviewed. It has got me a mixture of responses. >>


 

 

 

43.

Understanding: const char *p; and char * const q; Explanation.

 

44.

How to decipher the declaration: int(*f(char *c))(int, long*); Explanation. Thread.

 

45.

Dynamic linking vs. static linking. Read.

 

 

 

 

46.

A C program to print all combinations of a string. Program.

 

47.

How does the initialization, unsigned int i = -1;, take place?
Explanation. Explanation.

 

48.

There is a custom, of not casting the return value of malloc(), in clc. >>

 

49.

This program is not actually a FAQ, but an explanation of new features of C Language,
such as compound literals, function in-lining, etc. Read.

 

50.

Is the declaration: char c; same as signed char c; ? Explanation.

 

 

 

 

51.

How to detect signed integer overflow? Explanation.

 

52.

How can I set environmental variables from my C program? Explanation.

 

53.

A discussion on `pointer-to-function' usage. Read.

 

54.

Effects of passing a range of values to malloc() and free(). Read.

 

55.

How do I write a macro to find the address of a structure member? Explanation.

 

 

 

 

56.

An answer to a question explaining static and register storage class and
other. Read.

 

57.

A program to swap corresponding msb's and lsb's of a byte. Program. (See Q. 140)

 

58.

A program to convert a byte into bits representation. Program.

 

59.

What is structure padding? Explanation.

 

60.

Usage of setjmp macro and longjmp() function. Explanation.

 

 

 

 

61.

About: storage of character string literals. Read.

 

62.

Can a C program do I/O to/from other than keyboard or file? Explanation.

 

63.

What is conditional compilation? Explanation.

 

64.

A discussion on usage of restrict type qualifier. Explanation.

 

65.

How do I detect the endianess of my machine? Explanation.

 

 

 

 

66.

How do I write my own portable version of islower() function. Explanation.

 

67.

How do I trace my C programs? Explanation.

 

68.

Is it OK to copy a structure to another using strcpy()? Explanation.

 

69.

Does the definition char s[500000]; invoke undefined behaviour? Explanation.

 

70.

Storage of const qualified object. Explanation.

 

 

 

 

71.

What precautions should be taken while using strncpy()? Explanation.

 

72.

How do I edit the contents of a file? Explanation.

 

73.

Do different compilers have different contents in the same header file? Read.

 

74.

What is the order of parameter passing? Explanation.

 

75.

What is an assertion? (About: assert() macro) Explanation.

 

 

 

 

76.

How do I read a formatted file? Explanation.

 

77.

How C's data types are classified? Explanation.

 

78.

Why there is no logical XOR(^^) operator in C? Explanation.

 

79.

What precautions should be taken while using strtok()? Explanation.

 

80.

C99 introduces static storage class specifier for array type function parameters. Read.

 

 

 

 

81.

What is the return type of the signal() function? Read.

 

82.

Is not errno an extern variable? Explanation.

 

83.

What is allowed in C, but not in C++? Read.

 

84.

Why sizeof is an operator, not a function? Read. (see question 34)

 

85.

How to get the base address of the structure if I know the address of one member of the structure? Explanation.

 

 

 

 

86.

Why my code involving scanf() does not work? Explanation.

 

87.

Run-time data structure of a C program (with emphasis on static storage type). Read.

 

88.

Programmatically find the ranges of integral types without using <limits.h>. Read.

 

89.

Program to invert the given bit of a number. Read.

 

90.

A linked list puzzle. Read.

 

 

 

 

91.

What are magic numbers? Explanation.

 

92.

What is callback mechanism? Explanation.

 

93.

How do I multiply two integers using bit-wise operators? Read.

 

94.

How do I align an object to a particular boundary, say 4-byte boundary? Read.

 

95.

About the warning: "makes pointer from integer without a cast." Read.

 

 

 

 

96.

Can I return a two-dimensional array from a function? Read.

 

97.

How do I interpret: (*(void (*)())0) (); ? Explanation.

 

98.

An example of self printing program. Read.

 

99.

Is const char * const *p; a valid construct? Read.

 

100.

Why do I get the warning: "Non-portable pointer assignment" ? Read.

 


 

101.

How do I decipher: char *(*(*potter[N])())() ? Explanation.

 

102.

Why alloca() should be used carefully?  Read.

 

103.

What happens if the allocation size is zero in a call to malloc() ?  Explanation.  (See Q. 118)

 

104.

Does #pragma make a program non-portable?  Explanation. (See Q. 30)

 

105.

There exists a simple way to interpret pointer to kind of declarations.  Read.

 

 

 

 

106.

A note on type promotion.  Read.

 

107.

Why the size of the structure is not as I expect?  Read.

 

108.

Why my program raises a memory exception when I free() the allocated memory? Read

 

109.

How do I find the size of int during preprocessing stage?  Read.

 

110.

What are the different storage classes in C?  Read.

 

 

 

 

111.

What is the difference between strings and character arrays?  Read.

 

112.

What are register variables?  Read.

 

113.

How do I decipher the declaration: void *((*fnp[4])())(); Read.

 

114.

Does mentioning the array name gives the base address in all the contexts?  Read.

 

115.

Change an arbitrary switch statement with all its options into a collection of if-else-if statements.  Read.

 

 

 

 

116.

What is the best way to exit from main()Read.

 

117.

Which is faster: strcpy() or memcpy() Read.

 

118.

What is the usage of malloc(0); ? Read.  (See Q. 103)

 

119.

Is it possible to clear processor cache memory using C?  Read.

 

120.

What are the differences between calloc() and malloc() Read.

 


 

 

 

 

121.

How do I know if my machine (CPU) is a 64-bit one or a 32- bit one?  Read.

 

122.

How do I print the middle character of a file?  Explanation.

 

123.

A note of variable length arrays.  Read.

 

124.

A note of decaying of multi-dimensional arrays.  Read.

 

125.

What are dangling pointers?  Explanation.

 

 

 

 

126.

A note on different operations on arrays.  Read.

 

127.

What happens if a value - not defined by an enum - is assigned to the enum variable?  Read.

 

128.

What is device independent code?  (This is not a C question.)  Read.

 

129.

A C program to print a decimal number in binary format. Read.

 

130.

What is a tentative definition? Read.

 

 

 

 

131.

How do I implement linked-list using arrays? Read.

 

132.

A note on stack-frame base pointer and stack pointer. Read.

 

133.

A note on compiler vs. interpreter. Read.

 

134.

How do I find the size of RAM using C? Read.

 

135.

Range of enum in C++. Read.

 

 

 

 

136.

A program to rotate bits in an integer. Read.

 

137.

Is there a maximum combined length of command line arguments? Read.

 

138.

What are the differences between for/while and do-while loops? Read.

 

139.

Why header guards are required in the included (header) files? Read.

 

140.

A program to interchange bits in a byte (as shown in the program). Read. (See Q. 57)

 

 

 

 

141.

How can I set an array's size at run time? Read.

 

142.

How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters? Read.

 

143.

How do I access a local variable when a global variable of same name exists? Read.

 

144.

Assigning an unsigned long long to two unsigned long variables. Read.

 

145.

Difference between address of the first array element and the address of array. Read.

 

 

 

 

146.

Why do I get the “LValue required” error? Read.

 

147.

A not-so-good-usage example of goto. Read.

 

148.

A note on atexit() usage. Read.

 

149.

A note on accessing random memory locations. Read.

 

150.

What is the reason for this program (inside) to loop infinitely? Read.

 

 

 

 

151.

What is volatile qualifier for? Read.

 

 

 

 

Linux Questions

 

1.

What is U area? Answer.

 

2.

Two methods of using printers... Answer. Waveform.

 

3.

How to access a directory exclusively? Program.

 

4.

About: System call invocation. Read.

 

5.

Does the system go (or become) slow, if system call library is used (often)? Read.

 

 

 

 

6.

How do I get the physical address for a given virtual address?  Read.

 

7.

What are differences between a task and a thread?  Read.

 

8.

What are differences between segmentation fault and page faultRead.

 

9.

Working of Hardware Abstraction Layer (HAL). Read.

 

 

 

Links to other sites on the Web

Download this page!
C++ Vs C
Usenet C FAQs
The C Language Calling Sequence by Dennis Ritchie
Solution(s) to K&R Exercise
Have you formed an opinion?

Page Count:    Counter

© 2000 vijay.zanvar@wipro.com