Jump to content
PoisonousPython

C printf weird stuff...

Recommended Posts

Inainte sa postez asta pe Stack Overflow, m-am gandit sa o postez aici.

 

De ce functioneaza codul asta?

 

#include <stdio.h>

 

int main(){

       printf("blabla"   "321"   "wow");

}

 

E ca si cum string-urile s-ar concatena automat... Probabil e ceva de la compilator desi nu cred. De mentionat ca folosesc GCC 7.1.1.

 

EDIT:

Mda. Am gasit raspunsul. Pentru toti cei care sunt curiosi: https://stackoverflow.com/questions/14035769/concatenating-strings-in-a-printf-statement

Edited by PoisonousPython
  • Upvote 2
Link to comment
Share on other sites

In plus:

Stringurile "abc" "test" "123" sunt statice, declarate la compilare. Stringurile de acest tip (statice, scrise in cod) sunt destul diferite fata de pointer to char.

Compilatoarele trateaza stringurile hard coded intr-un mod special. 

Auto-concatenare(lipite impreuna)

Reducere(daca declari "test" de 2 ori in cod compilatorul va aloca spatiu pt un singur string si va creea 2 referinte)

reducere logica, read only memory etc.

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...