English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i am in search of proper guidence in c language.

2006-10-29 01:29:54 · 2 answers · asked by sanjay 1 in Computers & Internet Programming & Design

2 answers

Hi Sanjay,

In C the arithmatic operators work only with the simple data types i.e. int, chars etc. That is because the compiler/language knows the semantics of a predefined data type. Comparing a integer with another means comparing the value of the variables. Comparing a character with other means comparing their ASCII values.
Now when we talk about structures they are more complex. Such as a structure representing student. A structure for a student can contain his name and his section. Comparing one student with another student would not make sense for the compiler since it would not know whether the structures should be compared on basis of name or section. In such a scenario it is best to leave the comparison symantics to the programmer.

In C++ a programmer can overload the arithmetics operator and provide implementation for the arithmetaic operators for structures/classes. So the structures/classes can be used with arithmetic operators as in-built data types in C++. But if the programmer does not overload the arithmetic operator then the compiler issues an error since the compiler cannot know the symantics of a structure whether it is C or C++.

2006-10-29 10:13:26 · answer #1 · answered by Achint Mehta 3 · 0 0

The question is not clear. Can you explain with an example?
Aritmetic operators like +,-.* and /, can work only with int, float and double, as there the meaning of these operations are well defined. Even for string + works, as the meaning is concatenating. But for structure variables, how can you use these operators, if you dont know what should they perform?

2006-10-29 10:34:42 · answer #2 · answered by manoj Ransing 3 · 0 0

fedest.com, questions and answers