You're trying to use a local variable, which ceases to exist when the function returns.

int addEmployee(void)
{
    struct employeelist employee[5];
    /* ... */
}

The variable employee only exists inside the addEmployee() function; and it is a different object every time the function is called.

int printEmployee(int emp)
{
    struct employeelist employee[5];
    /* ... */
}

This employee has no relation to the one in addEmployee.


But don't do the easy thing now (*); do the right thing: declare the array in the main() function and pass it around.

//employee.h

struct employeelist 
{
    char last [20];
    char first[20];
    int pnumber;
    int salary;
};

/* add up to `maxemp` employees to the array and
** return  number of employees added */
int addEmployee(struct employeelist *, int maxemp);

/* print all employees from index 0 to (nemp - 1) */
int printEmployee(struct employeelist *, int nemp);

Declare an array in main(), and pass it around

#include "employee.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main ()
{
    int emp;

    struct employeelist employee[5]; 
    int emp = addEmployee(employee, 5);
    printEmployee(employee, emp);
    return 0;
}

(*) Don't declare a global variable for employees


Edited employee.h and added a main() function

Answer from pmg on Stack Overflow
🌐
GITAM
gitam.ac.in › wp-content › uploads › 2024 › 03 › PROG-C-AND-DS-LECTURE-NOTES.pdf pdf
PROGRAMMING IN 'C' AND DATA STRUCTURE
Fundamentals of C : Algorithms an Flow chart, C as a middle level language, Structure of C program, Character set, Identifiers, keyword, data types, Constants and variables, statements, expression, operators, precedence of operators, Input-output, Assignments, control structures decision making and branching.
Discussions

Programming with functions and structures using C, getting ...
I'm learning a bit C and i'm doing an exercise where i use structures and functions to collect employee infos and just print them out. I'm declaring the functions and the struct in the header sinc... More on stackoverflow.com
🌐 stackoverflow.com
Is it worth learn Data structures and algorithms in c?
Learn DS&A in a language with clear notation for pointers and data types. I think you can learn this in Python, but I think C is the most clear when reading an example in terms of what the types are and what is a pointer. More on reddit.com
🌐 r/C_Programming
73
120
December 1, 2023
Data Structures
Mastering Algorithms with C seems to satisfy what you want, with the added bonus of the provided implementations being written in C. More on reddit.com
🌐 r/C_Programming
13
8
July 13, 2024
How to implement type-independent data structures in C ?
you can use a void * as has been mentioned. The other thing I've done in the past, to avoid preprocessor macros, was to implement a struct like this; struct item { int item_type; size_t item_size; void *item_ptr; }; I mean, it's all taste really, and whether you really want to spend the effort. And there's a performance cost to this approach. It really depends on what you're doing. If you have a stack that's only ever going to store the same things, then you don't need to do that. But you know, it gives you the ability to say, give me the next item of type blah, and let you store different types in the same stack, and know how big they are, if they are things like char arrays. More on reddit.com
🌐 r/C_Programming
29
30
September 8, 2018
People also ask

What are data structures in C
divnbspData structures in C include arrays linked lists stacks queues trees and graphsdiv
🌐
scholarhat.com
scholarhat.com › home
Getting Started with Data Structures in C
What is the function of data structures in C
divnbspData structures in C organize and manage data efficiently allowing for optimal storage retrieval and manipulationnbspdiv
🌐
scholarhat.com
scholarhat.com › home
Getting Started with Data Structures in C
🌐
Programiz
programiz.com › c-programming › c-structures
C struct (Structures)
In this tutorial, you'll learn about struct types in C Programming. You will learn to define and use structures with the help of examples. In C programming, a struct (or structure) is a collection of variables (can be of different types) under a single name.
🌐
WsCube Tech
wscubetech.com › resources › c-programming › programs
C Programs (Code Examples With Output)
Functions for Organised Code: Function-based examples show how large tasks are divided into smaller pieces, a technique used in every kind of software to keep the code neat, reusable, and easy to maintain. Structures for Real-World Models: Using structures teaches you how to represent real items like employee profiles, product details, or customer data.
Find elsewhere
🌐
ScholarHat
scholarhat.com › home
Getting Started with Data Structures in C
August 2, 2025 - Effective utilization of the data structures leads to program efficiency. In this C tutorial, we'll delve deep into the data structures used in the C language. We'll understand various types of data structures with examples. At the end of the tutorial, you'll differentiate different data structures based on their characteristics.
🌐
IncludeHelp
includehelp.com › c › structures-find-output-programs-in-c-set-1.aspx
Structures - find output programs in C (Set 1)
No, we cannot initialize any member of the structure with in its declaration. ... #include <stdio.h> int main() { struct tag{ int a; float b; }; struct tag t={10,10.23f}; printf("%d, %.02f\n",t.a,t.b); return 0; } ... Structure members can be initialized while declaring its object (structure variable) like struct tag t={10,10.23f}; 4) Is the following structure variable declaration is correct? If yes, what will be the output of following program?
🌐
w3resource
w3resource.com › c-programming-exercises › structure › index.php
C Programming Structure Exercises, Explanations, Solutions
October 16, 2025 - Define a structure named Circle to represent a circle with a radius. Write a C program to calculate the area and perimeter of two circles and display the results. ... Create a structure named "Employee" to store employee details such as employee ID, name, and salary. Write a program to input data for three employees, find the highest salary employee, and display their information.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › what-are-the-c-programming-concepts-used-as-data-structures
What are the C programming concepts used as Data Structures - GeeksforGeeks
July 15, 2025 - But what if the data we want to store is more complex? Let’s consider an example, we want to store information of the students in a class in a single variable. So, a student has : ... Here, Roll number is of integer type and Name is string(array of characters) type. ... Structure is a collection of variables(can be of different data types), under a single name.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › what are the data structure in c and how it works?
What are the Data Structure in C and How it works?
September 25, 2024 - Join our C Programming Course and learn C syntax, operators, expressions, control flow, functions, pointers, structures, file handling, memory management, and modular programming. Build real-world skills through practical projects! ... #include <stdio.h> int main() { //array declaration int rollNo[10]; //taking inputs for(int i=0;i<10;i++) scanf("%d",&rollNo[i]); //printing for(int i=0;i<10;i++) printf("%d ",rollNo[i]); return 0; } Input: 12 13 34 56 12 87 56 78 23 10 Output: 12 13 34 56 12 87 56 78 23 10
🌐
Udemy
udemy.com › it & software
Data Structures and Algorithms in C for Beginners
January 4, 2023 - Welcome to the course Data Structures and Algorithms in C for Beginners. This course gives all the necessary content on various data structures like Arrays, Stacks, Linkedlists, Queues, Trees and Graphs and how to implement them using C Programming.
Rating: 4.3 ​ - ​ 410 votes
🌐
Teachics
teachics.org › home › data structure programs in c​
Data Structure Programs in C​ | Teachics
August 15, 2022 - Learn Data structures by practicing data structure programs in C. A data structure is a collection of data elements that provides an efficient method of storing and organizing data in a computer so that it can be used efficiently. Data Structures are essential components of many computer science ...
🌐
Itsourcecode
itsourcecode.com › home › data structures in c with advanced examples
Data Structures in C with Advanced Examples - Itsourcecode.com
November 10, 2023 - How can we use a student structure that we constructed to store student data that includes data members like student name, student class, and student sections? Structure variables must be created in C before we can use the built structure’s properties. The structure variables function as global variables if they are declared along with the structure definition (which means they can be accessed in the whole program).
🌐
W3Schools
w3schools.com › dsa › dsa_intro.php
Introduction to Data Structures and Algorithms
In this tutorial, you will first learn about a data structure with matching algorithms, before moving on to the next data structure. Further into the tutorial the concepts become more complex, and it is therefore a good idea to learn DSA by doing the tutorial step-by-step from the start. And as mentioned on the previous page, you should be comfortable in at least one of the most common programming languages, like for example JavaScript, C or Python, before doing this tutorial.
🌐
DEV Community
dev.to › mrpaulishaili › an-introduction-to-the-c-programming-language-290c
Introduction to C Programming and Data Structure. - DEV Community
August 22, 2023 - Structuring the code using functions ... the program more organized and less prone to errors. Dynamic Memory Management: One of the most significant features of C language is its support for dynamic memory management (DMA). It means that you can utilize and manage the size of the data structure in C during runtime. C also provides several predefined functions to work with memory ...
🌐
Medium
medium.com › @anthonybaxter819 › data-structures-in-c-a3ca04ca1a4a
Data Structures in C. The Building Blocks of Programming | by Anthony Baxter | Medium
July 10, 2025 - “Bad programmers worry about the code. Good programmers worry about data structures and their relationships.” · With that in mind, this series walks through the implementation of several of the most common data structures using only the C standard library.
🌐
GitHub
github.com › bartobri › data-structures-c
GitHub - bartobri/data-structures-c: A collection of algorithms for data structure manipulation in C · GitHub
A collection of algorithms for data structure manipulation in C - bartobri/data-structures-c
Starred by 118 users
Forked by 32 users
Languages   C
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › data structures in c
Data Structures in C: Types, Examples, and Usage
May 6, 2025 - Learn about Data Structures in C, including arrays, linked lists, stacks, queues, trees, and graphs. Understand their usage, benefits, and examples for efficient coding.
🌐
W3Schools
w3schools.com › c › c_structs.php
C Structures (structs)
You can also assign values to members of a structure variable at declaration time, in a single line. Just insert the values in a comma-separated list inside curly braces {}. Note that you don't have to use the strcpy() function for string values with this technique: