Thread: function as structure variable

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    26

    function as structure variable

    Hello,

    I'm following this video Tic Tac Toe using c - YouTube to develop a Tictactoe game. In which the developer is using a structure and it's declared like this
    Code:
    struct myDataType {
        int a;
        char b;
    }inputValue();
    and then use a function

    Code:
    struct myDataType inputValue() {
    
    }
    Is inputValue() a stricture variable??
    Can someone explain to me the syntax of this? with an example if possible??



    I've only see structures define as below so far

    Code:
    struct test {
        int test_member1;
        char test_member1;
    }test_variable;

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    No, inputValue() is a function that returns a structure. Although, IMO that code should be written as:

    Code:
    struct myDataType {
        int a;
        char b;
    };
    
    struct myDataType inputValue();
    This IMO is much clearer as to the intent of the statement.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    So just like creating a structure variable we can create a function that return a structure.

    Can you show a simple example to me??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 08-04-2017, 07:42 AM
  2. Replies: 10
    Last Post: 03-18-2014, 10:43 AM
  3. Function overloading by passing structure variable
    By infantheartlyje in forum C Programming
    Replies: 9
    Last Post: 10-15-2011, 02:15 AM
  4. Replies: 4
    Last Post: 04-25-2010, 10:57 AM
  5. Replies: 1
    Last Post: 02-03-2005, 03:33 AM

Tags for this Thread