Quantcast
Viewing all articles
Browse latest Browse all 22167

Set more characters than declared without any warning

I've reproduced it with simple example:

#include <stdio.h>

int main(int argc, char **argv)
{
    char l1[16];

    sprintf(&l1, "%s", "Hello AKIT!!!!!!!!!!!!!!!!");
    printf(l1);
    printf("\n");
    return 0;
}

Even my var is declared as 16 characters length, I can put in it much more characters without any errors from compiler, and it even works. I'm expected that string will be cuted up to 16 characters but not. Why? And how I can get cutted string?


Viewing all articles
Browse latest Browse all 22167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>