Hot answers tagged

5 votes
Accepted

pset3 find INT_MAX

INT_MAX is defined in limits.h, which is a standard C header. INT_MAX: Maximum value for an object of type int (32767 or greater) You may wonder why find.c needs that? int straw = GetInt();...
user avatar
  • 18.4k
4 votes
Accepted

Why is int is of 4 bytes in CS 50?

The size of an int is dependent on the hardware and operating system environment that you are working with. It has historically had a lot to do with the type of processor in the system. Early ...
user avatar
  • 64.2k
3 votes
Accepted

In breakout, why use 12 char to store an int?

The question is hinting at you to think about why the array is initialized with a size of 12.
user avatar
2 votes
Accepted

How to Form a Single Integer from the Elements of an int Array?

Assuming you don't want to add them and store the result in a new variable. To print them concatenated to each other like 15, you may write something like this. printf("%d%d\n", x, y); To add them ...
user avatar
  • 17.4k
2 votes
Accepted

Pset1 Cash - Trying to round float value DURING computation and not after

The code seems far more complicated than necessary, but this seems to be because you're trying to handle the imprecise float storage problem unsuccessfully. This can be resolved by simply converting ...
user avatar
  • 64.2k
1 vote
Accepted

PSET 4 - Filter Grayscale

The reason is that if the code is doing division with all integers, it will do integer division, not normal division. Integer division will truncate the fractional part of the division. So, if the ...
user avatar
  • 64.2k
1 vote
Accepted

pset1 - CS50 directory not found for ./integer. Keep getting bash error - help?

Simply put, the file integer, the executable file, doesn't exist. Only the source code file integer.c exists. You need to make integer first, in order to compile the source code and produce the ...
user avatar
  • 64.2k
1 vote
Accepted

Vigenere error compiling: type int vs unsigned long

I assume the % strlen(key) is causing some type conversion. Your logic is wrong. First iterate the key to ensure all characters are alphabetic, and maybe also uppercase the key there if you want. ...
user avatar
  • 20.7k
1 vote
Accepted

find.c in Pset 3; int straw = get_int(); ./generate 1000 50 | ./find 127; From where and how it takes 1000?

get_int() has no knowledge of the "2nd argument from generate.c". Remember from the spec: You’ll be prompted to provide some hay (i.e., some integers), one "straw" at a time. As soon as you tire of ...
user avatar
1 vote
Accepted

Int/Float Conversion

This is because when a/b is performed the result is o form int type which is 0 since the .625 part of the result is gone due to the expression a/b being an int. When the value a/b (i.e 0) is assigned ...
user avatar
1 vote
Accepted

difference between string, pointer, array and int

i = 32768; No reason at all why this wouldn't work. First, the size of int is 2^32 at the appliance, not 2^16. Second, even if you enter a higher value, it will never segfault. It will wrap around ...
user avatar
  • 1,677
1 vote

return value of sizeof()

quoting the C99 standard (6.5.3.4 - 20): C89, like K&R, defined the result of the sizeof operator to be a constant of an unsigned integer type. Common implementations, and common usage, ...
user avatar
  • 17.4k

Only top scored, non community-wiki answers of a minimum length are eligible