C Programming: Can a structure return value?

naina755

naina755

@naina755-8AQ4s2 Oct 17, 2024
In c data type structure is present ,structure allow to use different data type like int,char in the same program,my question is ,is structure return any value ?if it return any value what is the reason,if structure not return any value than what is the reason behind this.please reply
I am new member so i do not know any thing about crazy engineer.if i asked any thing wrong then please correct me.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD May 9, 2010

    Re: c language

    Welcome to CE, naina.

    Can you clarify your question?

    In C a structure is a collection if different data types. That is, we can have int, char, float or another structure as its members.

    And a structure does not return a value, a function returns a value. You can return a structure variable from a function, like any other variable.
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep May 9, 2010

    Structure doesn't return anything it basically meant for user defined data types
  • sushant005

    sushant005

    @sushant005-tyt4WK May 9, 2010

    Structure cannot return value since it is a user defined data type.

    It contains the collection of heterogenous data type means different data type like int,char,float evan arays and other structures
    and its only a logical concept.
  • elizas

    elizas

    @elizas-kfoAOd Jun 14, 2010

    I declared a variable as “int” data type for a PatientId. It worked fine in local, but when that code went to LIVE, the application gave exception because in LIVE PatientId is too long to accommodate in int data type.

    So before declaring any variable we need to consider all the situations, application scope, environment .Even one code may be working fine today, after 1/ 10/20 days/months/years it will fail due to just due to data type declaration mistake.

    Think more; write less is the policy for better programming.

    My Experience No 2:

    I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

    “int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

    Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

    #-Link-Snipped-#