C Programming Tutorial 62, The Stack

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

When/If you get into an assembly language, this sort of thing is very useful. Also, I think it's important to have a gist of what's going on behind the code you write.

iTzAdamX
Автор

in my mind memory is a huge stack of addresses in which to store data, not like a grid :)

Shockszzbyyous
Автор

I'm not really sure what you're asking. There is no way to make an array without giving it a size. You could create a pointer, like this:

char *myArray;

Then you could start assigning values to it like this:

myArray[0] = 6;

But that doesn't really make any sense. The address stored in that pointer will be just some random value that happened to be on the stack. That assignment will most likely result in a segmentation fault because it will be accessing a random part of memory.

iTzAdamX
Автор

3:03
"memory is more like a grid"
Well, no, more like address locations stacked on top of each other, as you were drawing it.

OneTimWhatley
Автор

Ok, I''ve got it. Looks like the compiler deleted for optimization the unused variables in the program. After putting values/ to the variables and printing them on Screen, There comes "Bob" at the End.
#include<stdio.h>

#include<stdlib.h>

int main()
{
int i = 6;
char myStr[4] = "Bob";
short s = 2;
short s1 = 7;
char *someStr;
char c = 'c';
printf("%i %s %i %i %s %c \n %s", i, myStr, s, s1, someStr, c, &s + 1);

return 0;
}

haraldlutz
Автор

thnx a lot.. but can u make more videos on dynamic data structures in C?

SupachaiAbusali
Автор

Hi Adam.
Thank you for your tutorials.
I have a question, I would like to print address and value of an int:
int i = 6;
str[4] = "test";
printf("%i = %i\n", &str1 + 1,   &str1 + 1);

Thank you,

Corrado

corradoi
Автор

the visualization drawing is a really good way to teach, but how can u be so sure that the variables you create will pile up in the order that you initial them to be?

granceroblast
Автор

let's say you declare a string array, without initializing it ( it takes values from the user).
since the size of this array will depend on the user input, how will the program know how much space to keep for it?

what happens in that case?

MBlu
Автор

This Code does not function to me in 2019 CodeBlocks 17.12. To me the result is "4", not "Bob".

haraldlutz
Автор

so the short will be cast to 4 byte before pushed in the stack

mlabouardy
Автор

whats the fundamentals of this? what is stack knowledge use for?

thewhisperinyourears
Автор

Hey adam I'm not able to print the string when i pass the address of Bob as &s1+2...can u plz tell why not?

divyampatro
Автор

It's actually an image that I found on google.

iTzAdamX
Автор

we can only push a 4 byte in the stack !!

mlabouardy
Автор

"bottom of stack" :'D :P

simransingh
Автор

Often compilers will rearrange variables for speed and ease of access.

h tt p :// stackoverflow .

iTzAdamX
Автор

You're a liar, this video isn't sixty seconds long!

Rolo-Tony
Автор

not much understandable
pakistanis and Indians are much better to explain this

S.Maaz
join shbcf.ru