Lecture 2 | Programming Paradigms (Stanford)
Why Stack Overflow recommends it
Stack Overflow users link it when explaining how numbers are laid out in memory at bit level, and when asking about its float-to-short pointer casting example.
Recommended by 4 people across 4 different months, 2011 to 2020.
What it is
Lecture 2 of Stanford's CS107 Programming Paradigms, taught by Professor Jerry Cain. It covers C and C++ code, how integers and floats are stored in memory, binary addition and subtraction, and pointer casting examples.
What people said
Recommends InBetween · 2011-05 · Stack Overflow · on “Increment forever and you get -2147483648?”
It has a lot to do with how positive numbers and negative numbers are really stored in memory (at bit level). If you're interested, check this video: Programming Paradigms [this video] at 12:25 and onwards. Pretty interesting and you will understand why your code behaves the way it does.
Recommends Zombian · 2011-07 · Stack Overflow · on “underlying data structure for float in python”
This lecture is a pretty good insight to how the variables are stored in-memory and the professor includes an example that would give the unexpected results you are seeing. [this video] If you need to compare the numbers cast them both as integers first and you will notice that they do equal if you perform the test.
Recommends Inaimathi · 2012-05 · Stack Overflow · on “C and Erlang: Erlang Port example”
That was my own "non-C programmer" understanding, so take with grain of salt. It may also help to watch this [this video] . That's a ~5 minute segment wherein he talks about shorts specifically. There's also about 10 minutes of fairly useful examples at the ~20 minute mark [this video] .
Recommends ssd · 2020-03 · Stack Overflow · on “How can I store float variable to int array (C)?”
@P__J__ : Didn't mean (neither write down) that "C is a language of my own" but "a language of its own". I'm sure, you got what I meant. And, yes I know, pointer-punning is not a standard operation in C but one of the reasons C is loosely designed is those kind of non-standard operations; 'tweaks' literally. Again, whatever the comp. science lesson the questioner taking, I suspect, this [this video] part of the video (44:45 and following ~5 minutes) is the chapter s/he is currently learning.
Cites witherspoon · 2012-04 · Stack Overflow · on “C++: Asterisks, Ampersand and Star?”
Recently I came across this video on Programming Paradigms [this video] and the prof. used terms like Asterisks, Star, and Ampersand. This was what how he used those operators: int i = 37; float f = *(float*)&i; And how he voiced line 2 while writing it: Float "f" equals asterisk float star, ampersand of i I understand what asterisk and ampersand mean, but what is the significance of using star here? Is it synonymous to asterisk?
Cites elyashiv · 2012-08 · Stack Overflow · on “short pointer to a float”
i run this code in c++: #include <iostream> using namespace std; int main() { float f = 7.0; short s = *(short *)&f; cout << sizeof(float) << endl << sizeof(short) << endl << s << endl; return 0; } i get the following out pot: 4 2 0 but, in a lecture given in Stanford university, Professor Jerry Cain says he is sure the out pot well not be 0. the lecture is can be fond here [this video] . he says that around the 48 minute. is he wrong, or that some standard change since? or is there a difference between platforms? I'm using g++ to compile my code. EDIT: in the next lecture he does mention "big endian" and "small endian" and says that they well affect the result.
Cites JCob · 2014-11 · Stack Overflow · on “Casting pointer to other pointer”
Right now I'm watching this lecture: [this video] In around 50th minute of the film he says that this code will return non-zero value: float f = 7.0; short s = *(short*)&f; Correct me if I'm mistaking: &f is a pointer to float. We take &f and cast it to pointer to short. Then we dereference (don't know if it's a verb) that pointer so eventually the whole statement represents a value of 7. If I print that it displays 0. Why?
Critical user529758 · 2014-01 · Stack Overflow · on “Array Syntax Confusion in C”
@haccks See my comments (and the incoming ignorant responses) on this video [this video] . Armed with a fresh copy of the C99 Standard, any intermediately experienced C programmer can point out **literally dozens of errors** in the presentation of this guy.