Is memory allocated when the variable is not used in c -


#include<stdio.h> int main() {     int a,b;     float e;     char f;     printf("int &a = %u\n",&a);     printf("int &b = %u\n",&b);     printf("float &e = %u\n",&e);     printf("char &f = %u\n",&f); } 

the output

int &a = 2293324 int &b = 2293320 float &e = 2293316 char &f = 2293315 

but when use code , replace printf float--

#include<stdio.h> int main() {     int a,b;     float e;     char f;     printf("int &a = %u\n",&a);     printf("int &b = %u\n",&b);     printf("char &f = %u\n",&f); } 

then output

int &a = 2293324 int &b = 2293320 char &f = 2293319 

here address not provided float, declared on top. questions

  1. is memory not allocated variables not used in program?
  2. why addresses allocated in decreasing order. ex- it's going 2293324 2293320?

1) memory not allocated variables not used in program?

yes can happen, compiler allowed optimize out.

2) why addresses allocated in decreasing order. ex- it's going 2293324 2293320?

that usual local storage implementations, use cpu supported stack pointer going stack top stack bottom. local variables allocated @ stack probably.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -