Contact Us

Continuing on with C – Structures

The C programming language is a programming languages first created between 1969 and 1973 by Dennis Ritchie and has been the basis of many other programming languages since.

Here we will be carrying on from our initial post “Beginning with C” with a short lesson on structures

Structures with C

Structures are useful for when you want to have a single, specific name which you can then use to refer to a group of related values.

What are structures?

Structures give you the ability of storing a number of different values in variables of different types under the same name. Using structures makes our programs more modular and easier to modify as things become more compact.

Structures are useful for when holding lots of data together like database records or contact information.

Syntax

To define a structure called “Contact” we would simply type the following:

struct Contact {

Variables

};

To then create our structure we would do the following:

struct Contact person;

To then access our variables we would write the following:

person.variableName;

A full program is given below:

#include <stdio.h>

struct Contact {

int id;
int age;
float salary;

};

int main() {

struct Contact person;

person.id = 5;
person.age = 25;
person.salary = 12500.50;

printf(“ID: %dnSalary:%dnAge:%fn”, person.id, person.salary, person.age);

return 0;

}

Unions can also be used and are like structures except that all the variables share the same memory, but more on these later.

This is enough for today. If you would like any help with your web or development applications or projects then why not get in contact with us here at Network Intellect.

This article was posted by



Leave a Reply

What our clients say

"It’s like having your own in-house digital marketing consultancy rather than an external company. I no longer think about them as a supplier. They’re part of the team."
Marketing Manager, Education
"They have always been professional and focused on delivering results in a timely and cost effective manner. It is enlightening to have an organisation that takes the time to make recommendations on actual data analysis."
Business Manager, Charity
"They (Network Intellect) continue to exhibit their digital expertise by helping us to establish a competitive advantage by pushing the boundaries and innovating their technology and performance solutions."
Head of Marketing Communications, Education
"Because of their talent, expertise and level of service our on-line business has increased dramatically."
Founder, Electronics
"I would have no hesitation in recommending them as an analytics partner to understand and improve the performance of a website."
Vice President, Retail
Network Intellect continue to give us a fantastic service, fast and friendly and are always ready to go the extra mile. They have gone above and beyond the call of duty to deliver our results.
Director, E-Cigarette Web
"We found that Network Intellect had the depth of knowledge we needed and after speaking to them a few times we decided to go with them. It’s the best decision we’ve made in some time."
Owner, Retail
"Their services offered great value for money. I would not hesitate to recommend them as a digital partner to others."
Strategic Marketing Manager, Education
"Jason and his team at Network Intellect embody efficiency and efficacy. I would have no hesitation in recommending this excellent company to others."
Marketing Manager, Education
Network Intellect have managed our product data feeds with exceptional care and meticulous detail. I know I can trust them to make the right decisions for our business."
Director, E-Commerce
"It’s like having your own in-house digital marketing consultancy rather than an external company. I no longer think about them as a supplier. They’re part of the team."
Marketing Manager, Education
Read all testimonialsRead all testimonials

We can help you be great

We have friendly staff ready to help you get on your path to greatness...
Network Intellect Menu