Basic Types
Basic Types
Taken from: Feuer, A. R., (1999). The C Puzzle Book, 3rd Printing.
USA. Addison Wesley Longman Inc. Used for educational
purposes.
Basic Types
Basic Types 1: Character, String and Integer Types
Explain
Basic Types 2: Integer and Floating Point Casts
Explain
Basic Types 3: More Casts
Explain
Basic Types
C has a comparatively small set of built-in types. The arithmemtic
types may be blindly mixed in expressions, the results governed by
Basic Types 1
a simple hierarchy of conversions. This hierarchy is ilustrarted in
Appendix 4.
For some of the puzzles in this sectionsyou will need to knowt the
corresponding integer values of some chatracters. Appendix 3
show the values for the ASCII charater set. A few of the puzzles
yield a diferent result on the intel 8088 than motorola 68000. For
those puzzles, output from both machines is given.
#include <stdio.h>
int integer = 5;
char character = '5';
char *string = "5";
int main()
{
PRINT(d, string); PRINT(d, character); PRINT(d, integer);
PRINT(s, string); PRINT(c, character); PRINT(c, integer=53);
PRINT(d, ('5' > 5)); // Basic Types 1.1
{
int x = -2;
unsigned int ux = -2;
system("pause");
}
Basic Types 2
string = una dirección de memoria cualquiera
character = 53
integer = 5
string = 5
character = 5
integer=53 = 5
('5' > 5) = 1
x = 37777777776
ux = 37777777776
x / 2 = -1
ux / 2 = 2147483647
x >> 1 = 37777777777
ux >> 1 = 17777777777
x >> 1 = -1
ux >> 1 = 2147483647
Explain
#include <stdio.h>
int main()
{
double d;
float f;
long l;
int i;
Basic Types 3
}
i = 33 l = 33 f = 33 d = 33
i = 33 l = 33 f = 33 d = 33
i = 33 l = 33 f = 33.333332 d = 33.333333
i = 33 l = 33 f = 33 d = 33
i = 33333 l = 33333 f = 33333 d = 33333
i = 33333 l = 33333 f = 33333 d = 33333
Explain
#include <stdio.h>
int main()
{
double d = 3.2, x;
int i = 2, y;
x = (y = d / i) * 2; PRINT2(x,y); x = 2 y = 1
x = 1.6 y = 3
y = 2
x = 0 y = 0x = 2 y = 1
x = 1.6 y = 3
y = 2
x = 0 y =// Basic Types 3.1
y = (x = d / i) * 2; PRINT2(x,y); // Basic Types 3.2
Basic Types 4
x = 2 y = 1
x = 1.6 y = 3
y = 2
x = 0 y = 0
Explain
Basic Types 5