Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

implicit return value in C. This simple code should not work, but it does [duplicate]

$
0
0

I'm going straight to the point. This simple code should not return any values:

   #include <stdio.h>   int sum (int num) {        static int s = 0;        s+=num;   }   int main() {       printf("%d ",sum(55));       printf("%d ",sum(45));       printf("%d ",sum(50));       return 0;   }

but it actually returns:55 100 150

I'm sorry if I am being just plain stupid and not seeing something obvious, but my limited knowledge says the function "sum" does not return anything.

image for clarification


Viewing all articles
Browse latest Browse all 12111

Trending Articles



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