The set of statements that one can write as part of defining the block that constitutes the body of any function written in C falls broadly into two categories:
In this article, I have considered explaining only declarative statements. They are used to declare:
Anyone who has at least covered a primer on C is familiar with the meanings of these declarations. It seems like there’s nothing much to learn but it’s quite the opposite. Most of the students who are exposed to the language of C just study it for either they have to pass a semester exam or try some competitive coding platform to solve a few data structure and algorithm-related questions: none of these does consider writing some serious software in C.
Table of Contents
C is used to develop operating systems kernel, low-level device drivers, high-speed routing protocols, language runtime for other languages etc. Alas most of us are only interested in developing some superficial desktop or web applications and hardly have time for paying heed to the core computer science topics.
Long ago while studying Linux system programming (Beginning Linux Programming, 4th edition: Neil Matthew and Richard Stones) I came across the prototype of the signal handling function:
void (*signal(int sig, void (*func)(int)))(int);
Can you dissect the above declaration grammatically? Well, a signal is a function that takes two arguments-
Let’s dissect the function pointer argument itself: void (*func)(int). It’s a pointer to a function that receives an integer argument and returns nothing i.e., void.
Now the question arises: what’s the return type of the function ‘signal’? It’s the same function pointer that the signal has received. You are wondering exactly how I came to such a conclusion? Well, I have a few tricks at my disposal when I’m asked to dissolve a complex declaration in C.
Let me discuss those tricks in this blog.
Whenever I try to untangle the meaning of any declaration at first, I rank the declarators from higher to lower as follows:
|Function, Precedence Incrementor|
|Left to Right|
|2||*||Pointer||Right to Left|
|3||int, float etc.||Ordinary type declarators||N.A.|
Now if you want to analyze the above declaration of the signal function then first underline it as follows:
Look, I’ve numbered the sections by the precedence and associativity of the declarators. So, if you want to analyze what’s signal then you have to get inside section 1 first. Let’s analyze now section 1.
Obviously, the higher precedence of the () following signal makes it a function rather than a pointer (Look at the * preceding the word signal). Now, ‘signal’ is a function. If you want to dissect further about any function then ask yourself the following two questions:
Well, let’s try to answer these questions. To answer the first question just get inside the section number 1:
What do we see here? We see two arguments here.
Let’s analyze it now.
If we get inside section 1, we see that it’s a pointer. If you set your foot on a pointer while traversing various parts of a C declaration then ask yourself only one question:
Well, the answer can’t be found in section 1. If you get out of the surrounding parentheses of section 1 then you have to move to the right and not the left because the right section has more precedence than the left. You see there that it’s a function that can consume only one argument of type int.
Now you have to get out of this section if you want to know the return type of this function: it’s at the extreme left as it has the lowest precedence i.e., void. Look at the movements that I’ve made in the next diagram:
Well let’s get back to the earlier diagram:
Can you remember we asked ourselves two questions?
We answered only the first question. Let’s try to answer the second question.
You can’t get any knowledge about the return type inside the pair of parentheses following the function name: signal, so you have to move to the left and you see there is a * which signifies that the function returns a pointer. Now as I told you that whenever you come across a pointer when making a journey through the several parts of a C declaration ask yourself only one question:
Well, if you wanna answer this question you have to refer to the earliest diagram:
The answer can’t be found inside the surrounding parentheses of section 2 so let’s get out of it. Now you have to move to the right because the right section has more precedence than the left and we see there that signal returns a pointer to a function. Once again you set your foot on a function and you are going to ask yourself the same two questions:
Now we can answer these questions quickly. The answer to the first question is that the function receives an argument of type int. But if you want to answer the second question you have to go to the extreme left: the return type of the function is void.
Just refer to the following diagram to observe the movements that I’ve made:
Let’s refer to the above diagram to conclude the signal function’s prototype:
‘signal’ is a function that takes two arguments:
The ‘signal’ function returns a pointer to a function that takes an int as an argument and returns nothing i.e., void.
Convinced? If you have any doubt you can write to me or if you have some other complex declarations that you can’t analyze yourself, just send them to me. I will try my best to analyze them and write back to you I promise.
If you wish to learn C programming language in details and wish to turn yourself into an expert, then join Webskitters Academy. Industry professionals, like me, are always on their toes to help you enhance your technical skills and walk towards a bright future!
Also Read some of our other technical blogs,
“I think the Software Testing Course is apt for me. Webskitters Academy has offered me the best experience for online training. Every learner can learn more about several concepts. The assignments to write Test cases and Test case Scenarios equipped me to learn to work on real-time projects. I got a job at a reputed firm with the help of the placement cell of this institute. I am extremely happy.”
“After the Software Testing course at Webskitters Academy, I now have the confidence to face testing interviews. I trusted the institute and here they gave me the best of the best. The assignments are great and they helped me to think out of the box and come up with new questions. I am extremely happy and satisfied and also got a job through this institute.”
“I am 100% content with the Software Testing course at Webskitters Academy. The professionals explain every question and doubt that aroused in my mind. The entire course is explained the thorough and step-by-step process. It is very professional but the learning method and environment are very friendly.”
“I am glad that I took the decision of joining Advanced PHP and MVC (Laravel) online course at Webskitters Academy. I joined the course during the lockdown, to learn programming. However, it is turned out to be more than just a course. It became my passion. The tutors were so good and encouraging. I even got a good placement during the pandemic, just a few days after the completion of the course.”
“Learnt PHP Laravel under Swarup Kumar Saha Sir. He is very helpful and excellent trainer. I am done this course online. The training was good I improved my coding skill and also improved my communication skills.”
“Learnt PHP With Laravel under Swarup Kumar Saha Sir. He is an excellent trainer. The training was good I improved my coding skills as well as communication skills.”
“I did training on Android App Development using Core Java from here. I guess, I couldn’t have find a better faculty than Swarup Sir. The thing I liked the most is that he is very friendly and always eager to help us on any terms. Apart from teaching us Android in a very great way, he helped us in personality development too, as he always motivated us in a good way. So, I guess these training days were not only for learning but also for finding our own skills and mastering them. Thanks to Webskitters for providing us this opportunity. I would like to learn more from here.”
“I had a fantastic experience with this academy. I trained by professionals. I learned Android App Development using Core Java properly and got a job very early in a reputed software company through this academy. Many many thanks to Amit sir, Riyanka ma’am and Debjit sir.”
“I have done Android App Development using Core Java training from this academy for one month. They cover most of topic in one month. Trainer (educator) was very supportive and polite.”
“Right after completing my Android App Development with KotlinCourse at Webskitters Academy, I landed a job in a reputed firm. This was an incredible experience for me as before that I was looking for a job for almost a year but failed to get any. Thanks to the professional training I took from the experts that helped me start my career instantly.”
We are glad to have hired the students from Webskitters Academy! We have to mention that they are trained to be the professionals. From the first day onwards, they have shown their excellence, and it is very impressive. Our team is also happy with their involvement and performance. Looking forward to hire more excellent students from them!
We are happy with the quality of training that the Webskitters Academy students have received. Few of them have been on-board with us recently and they have impressed us. We would recommend our associates to hire freshers from this institute, they make sure that the students are well-trained and prepared for the industry.
We hired the students from Webskitters Academy and to our surprise we found out that they are brilliant in their work! No way we can call them students, they are professionals. They know their work, have the skills and are well-groomed for the profession. Thanks, Webskitters Academy for such a comprehensive training!
“It was for the first time that we hired students from Websitters Academy. We had some doubts regarding freshers, but to our surprise, they are very good in their work. They know exactly how to do a particular job keeping the industry standards in mind. Our organization is happy to have them. Their codes, and development skills are perfect, suitable for the industry. It proves that they have been trained comprehensively. Good work by the faculties of Webskitters Academy. We will definitely recruit more young talents from you.”