UrbanPro
true

Take BTech Tuition from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

In fresher interview technical round, you may get confused with some object oriented "look a like" features of C language.

Adroit Learning Foundation
26/09/2016 0 0
Sometimes C looks like to follow object oriented paradigm. Don’t get carried away withis idea. Current note focuses on this.
Star (*) Operator in C language acts both as pointer and multiplication. Then could we say that C supports Operator Overloading?
C language certainly does not obey operator overloading. In operator overloading, the function of the operator becomes different, but the arity of the operator never changes. Here when * acts as a multiplier it is binary in nature, but when it acts as a pointer, it acts as a unary operator. Hence this example never follows the condition of operator overloading regarding the arity of the operator and so by citing this example, we cannot say that C supports operator overloading.
In C language, printf function takes different number and different nature of arguments in every time. Is it the example of Function Overloading?
No way! C does not support function overloading at all. The functions print() is capable of accepting different numbers of arguments due to an operator ellipsis which is represented as … (just three dots, nothing else!)
If we look at the prototype of printf, it would say something like
int printf(const char*, …);
The second parameter is the ellipsis and it uses four different predefined macros va_list, va_start, va_arg and va_end. Ellipsis essentially says that there could be any number of arguments. This what printf() is backed with, certainly this is not a valid example of function overloading. Because in function overloading the numbers of arguments are specific, for example a function accepting two parameters can be made to accept three parameters (or so), but the instances, two or three are specific. Again in function overloading, the type of parameters can be changed, but once again the set is fixed like a function can act to accept a float and an int, but any data type with function overloading? Just forget it out.
So we are left with to demystify how printf() can accept any data type! This is done by parsing the first parameter of the printf that is const char* which is a string essentially. As we all know, this string contains different format specifiers like %d, %f etc, these specifiers peels out the knowledge that what is type of corresponding argument.
For example if we use
printf(“The results are = %d %f”, i_val, f_val);
Then in the va_list macro, that is in the list of (v)ariable (a)rgument, there will be two arguments. By parsing the mandatory format string, the type of the first argument is computed as int and the second argument is fixed as float.
Now the question is where is this parsing algorithm present? This algorithm has been implanted within the definition of printf().
0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

What is cement?
A cement is a binder, a substance used for construction that sets, hardens, and adheres to other materials to bind them together. Cement is seldom used on its own, but rather to bind sand and gravel together....

Language of mathematics (IMP Tip for Engineering Students)
From childhood we are often asked which is our favourite subject. We, without batting an eyelid would say the subject which we aced which most likely is MATHS. Because the examiner has least bit of chance...

Venu Gopal

0 0
0

Easy way to remember Java keyword.
ACCESS MODIFIER ACCESS SPECIFIER abstract, assert, const, final, native, static, strictfp, super, synchronized, this, transient, void, volatile public, private, protected, default DATA...

Rohit Deshbhratar

1 0
0

Introduction to Programming Languages
What is a Programming Language? A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages...

Polarization of Plane Waves
(a) Linear polarization A plane wave is linearly polarized at a fixed observation point if the tip of the electric-field vector at that point moves along the same straight line at every instant of time. (b)...
X

Looking for BTech Tuition Classes?

The best tutors for BTech Tuition Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Take BTech Tuition with the Best Tutors

The best Tutors for BTech Tuition Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more