Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3490738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:33:08+00:00 2026-05-18T11:33:08+00:00

Hello i’m selfstudying C and i’m a bit confused about the following code since

  • 0

Hello i’m selfstudying C and i’m a bit confused about the following code since i don’t know if i’m understanding the code properly. I would be very thankful if someone could read my explanation and correct me if i’m wrong.

The code is from a header file. The function of the program should be uninteresting at this point, since my comprehension problem is about the pointers and the values the functions give back. So first of all i’m declaring 3 arrays of char and an integer in my employee struct.

struct employee
{
    char firstname[11];
    char lastname[11];
    char number[11];
    int salary;
}

5 functions are declared in the header file. The first function takes 4 values (3 pointers and one int) and gives back a pointer to a struct. The second function gets a pointer to the “struct employee” and gives back a pointer to an element of the array “char firstname” in the struct employee. The functions 3 and 4 are doing the same for the other both arrays.
The function 5 gets a pointer to the struct employee but gives back an int and not a pointer. So it is just using the declared variable in the struct.

struct employee* createEmployee(char*, char*, char*, int); //1
char* firstname (struct Employee*);                        //2
char* lastname (struct Employee*);                         //3
char* number (struct Employee*);                           //4
int salary (struct Employee*);                             //5
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:33:09+00:00Added an answer on May 18, 2026 at 11:33 am

    Your understanding is pretty much correct. To be a little more accurate and/or less abusive of the English language, functions 2-4 return a pointer to an element of the corresponding array.

    The idea is that the contents of each array represent some kind of text, with each element corresponding a character of text, up until the first appearance of a zero value (used to mark the end of the “string”). Keep in mind that there is no provision for Unicode here, or even for specifying an encoding: we assume ASCII, and for any bytes not in the range 0..127, all bets are off. A better name for the type char would be byte; but we didn’t really know any better back then. (You should also be aware that char is a separate type from both signed char and unsigned char, and that char may or may not be signed.)

    This way, the names and number can be any length up to ten (an 11th byte is reserved in order to have room for the “null terminator” with the zero value), and the returned pointer can be used to inspect – and modify; but that might not be a good idea – the data in the arrays that are part of the Employee structure.

    The int returned as the Employee ‘s salary is a copy of the one in the struct. So although we can see the whole value, this does not let us modify the value in the struct. Of course, as long as we have the struct definition and an Employee instance, there is no protection; we can access the member directly instead of going through the function.

    In C, we get “encapsulation” and “data hiding” by not providing these definitions. Instead, we would just put struct Employee; and the function declarations in the header, and the struct definition in the implementation file. Now calling code doesn’t know anything about what an Employee is; only about what it can do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello everyone I am newto programming and I am just a little bit confused.
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I need to generate a report which would include both data and a
Hello I am using jquery layout plugin from http://layout.jquery-dev.net/ . my options are following:
Hello I have a Problem with some Buttons I would like to create a
Hello everyone i need to convert this code to a function with 2 parameters
Hello in my java class Toto, I have 3 static methods I would like
Hello I am trying to do a SOAP request here is my code: #
Hello all in my iphone application after sending login xml request am getting following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.