Before I ask my question, some background may be apposite to provide context. Please indulge me.
At the institute I teach, our Intro to Programming. It involves a coverage of C language. We believe C is the most foundational and least verbose of most of the popular and heavily used modern languages, such as C++, C#, Java, Python etc. (you may not agree with our position, but that’s a discussion for another day).
Our institute trains people in various trades and skill areas including programming. We try to attract people to programming, by allowing them to take our Intro to Programming course regardless of what they registered to learn.
Our Intro to Programming class thus is a mix of different students from different backgrounds and at different levels of education (O’ level students looking to prepare for exams or learn a skill, under- and post grads, self-taught people, professional programmers crossing over to C who feel they need a sound foundation, our registered programming trainees etc.)
We attempt to give them sound fundamentals covering history of programming, basic concepts, variables, i/o, sequential, branching and looping constructs, doing maths with C, functions, data structures fundamentals, arrays and pointers. After covering up to arrays and pointers, we teach them C-structs.
My experience has been: the students learn up to arrays easily, get some trouble with pointers but get by after a lot of scaffolded and non-scaffolded exercises. However, when it comes to C-structs, it takes a lot of effort to get them to understand even the basic concepts of C-structure members and struct variables. They confuse struct members with variables and try to declare or access members the way they would an ordinary variable as I would show below.
Though I try to make the concept of structs as intuitive as possible, I run regularly in to this confusion in students. Consider this snippet below, as a typical example of what I use to introduce structs. The example, struct
MyshoppingCart has 3 members (
meatKgs) and 3 variables: my cart content for Monday (
cartM), for Wednesday (
cartW) and my cart contents for Sunday (
struct MyshoppingCart // struct definition
float grainKgs; // struct members
} cartM, cartW; // struct variables declaration type 1
struct MyshoppingCart cartS; // struct variable declaration type 2
With a simple struct like this, students show three difficulties.
If you tell them
cartWin the example above are struct variables, they ask why then are they not declared inside as members like
double grainKgs;If I explain they are not inside because they represent an instance of the structure, they get more confused.
If I try to explain different ways to declare struct variables i.e. method 1: right after and following the closing brace of the struct definition and method 2: inside main using the name of the structure as prefix, the confusion increases.
It takes lengthy explanation and many examples to get some semblance of understanding from many of the students.
When you get to accessing members of the structure and you tell the students, we can do this by using the dot notation as in:
cartM.orangeNos = 5;
cartS.meatKgs = 3.7;
printf("No of oranges in my Monday cart is %d\n", cartM.orangeNos);
printf("Mass of Meat in my Sunday cart is %.2f\n", cartS.meatKgs);
A student will just go ahead in accessing say
orangeNos; to write something like:
printf("No of oranges in Monday cart is %d \n", orangeNos);
You tell him/her it’s wrong and: All hell just gets foot lose! They… just…. don’t …. get it …..EASY! He/she gets more confused!
My Question is:
Are these difficulties symptoms of cognitive overload? Or what could be the likely problem?
I have tried questioning students, but I have not gotten answers that may give me insight to the root of the problems.
Has anyone encountered similar problems teaching C-structs and how did you overcome it; getting students to learn it like a breeze? Please share your experiences or even suggestions you think might help me make learning structs easier and less herculean for my students.