Question: I am getting date value from API as "date\_display":"13/03/2018". Now how to display the date as 13 MAR 2018 and how to get the day value for this date and show it in TextView?

```
protected void onPostExecute(String result) {

        super.onPostExecute(result);
        //text.setText(result);
        try {

            JSONObject obj = new JSONObject(result);

            JSONArray airlinesArray = obj.getJSONArray("data");
            for(int i = 0; i < airlinesArray.length(); i++){
                JSONObject object = airlinesArray.getJSONObject(i);

                String id=object.getString("id");
                String rt=object.getString("route_type");
                String flightname=object.getString("flight_name");
                String fno=object.getString("flight_no");
                String dd=object.getString("date_display");
 HashMap<String, String> airliner = new HashMap<>();

                airliner.put("id",id);
                airliner.put("route_type",rt);
                airliner.put("flight_name",flightname);
                airliner.put("flight_no",fno);
                airliner.put("date_display",dd);
ListAdapter adapter = new SimpleAdapter(
                MainActivity.this, airlines,
                R.layout.details, new String[]{"flight_name", "flight_no",
                "date_display","time_display","display_route"}, new int[]{R.id.flightname,
                R.id.flightnum, R.id.date,R.id.time,R.id.route});

        lv.setAdapter(adapter);

```

Answer: 
A compound literal declared inside a function has automatic storage duration associated with its enclosing block (C 2018 6.5.2.5 5), which means its lifetime ends when execution of the block ends.

Inside `numbers`, `*p = (int []){1, 2, 3};` assigns the address of the compound literal to `*p`. When `numbers` returns, the compound literal ceases to exist, and the pointer is invalid. After this, the behavior of a program that uses the pointer is undefined. The program might be able to print values because the data is still in memory, or the program might print different values because memory has changed, or the program might trap because it tried to access inaccessible memory, or the entire behavior of the program may change in drastic ways because compiler optimization changed the undefined behavior into something else completely.
It depends on where the compound literal is placed.

C17 6.5.2.5 §5

> 
> The value of the compound literal is that of an unnamed object initialized by the
>  initializer list. If the compound literal occurs outside the body of a function, the object
>  has static storage duration; otherwise, it has automatic storage duration associated with
>  the enclosing block.
> 
> 
> 

That is, if the compound literal is at local scope, it works exactly like a local variable/array and it is *not* safe to return a pointer to it from a function.

If it is however declared at file scope, it works like any other variable with static storage duration, and you can safely return a pointer to it. However, doing so is probably an indication of questionable design. Plus you'll get the usual thread-safety issues in a multi-threaded application.