c - Can arrays inside functions be initialized with the return value of functions?Is "int arr[2]={strcmp("a","a"),strcmp("3","5")};" correct? -


aren't variables of static storage type expected not initialized return values of functions not considered constants?going argument,isn't following declaration valid in c.it compiles without error or warning,and output expected.

#include <stdio.h> #include <string.h>   int main () {    int arr[2]={strcmp("a","a"),strcmp("3","5")};   printf("%d,%d",arr[0],arr[1]); } 

result 0,-1

the statement static variables can not bet initialized return values of functions true, in exemple, arr not static variable, variable stored on stack, piece of code totally valid.

on other hand, writting:

static int arr[2]={strcmp("a","a"),strcmp("3","5")}; 

would illegal, reasons explained.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -