Sunday, July 26, 2009

C++ questions, cansomeone please?

why? i just need a short answer... thanks





a) Omitting the semicolon at the end of a statement is a syntax error. why?





b) All variables in a program must be declared before they are used. why?





c) A syntax error will occur if any of the operators ==, !=, %26gt;=, and %26lt;= appears with spaces between its pair of symbols. why?








d) Forgetting to include the iostream file in a program that input data from the keyboard or outputs data to the screen causes a compiler error. why?





e) C++ considers the variables number1 and numbeR1 to be identical?





f) The following identifiers are all valid variable names: _num1_, num_1, a123,


int1, a2a, z22, z2z, 2z2, zzz, because?





thanks... i just really need to compare answers :)

C++ questions, cansomeone please?
a) Yes, you're right, many languages use semi-colons and such as statement separators whereas they are absolutely required at the end of every statement in C, even if it's the last one in the file.





b) Right again, because this helps to identify typos basically and finding bugs due to misspellings of variable names can be a real headache in languages that do not require declaration. But you can use variables in C++ immediately even in the same statement where they are declared, so this isn't arduous or a big negative.





c) Right, because "=" has a meaning different from "==" etc etc, just like "%26gt;" has a meaning different from "%26gt;=" so there's no way to tell what the programmer means if you allow "%26gt; =" as a way of saying "%26gt;=", or at least it makes the compiler's job much more difficult. C++ does have to be processed by a compiler.





d) Right, because C and C++ have always been relatively unique in being defined strictly as languages, meaning that "print" functions and such are responsibilities "offloaded" to library functions. So there is no built in idea of "print" like there is in many languages. You have to bring in a library to do that. This is a good thing in my opinion and is one of the things that makes C/C++ usable in all contexts...





e) No, wrong. number1 and numbeR1 are different names and different variables. You can't refer to number1 using "numbeR1".





f) Yeah, I think so, what's the problem? You don't like those names? You think the language should somehow mandate people using variable names that you like? You think variables should have to have more than 3 characters? Many programmers like to use "a" "b" and "c" in some stretches of code, you have a problem with that?





Hope that helps!
Reply:you said "a" short answer, well do you really expect anyone to spend half the night trying to find if your questions are valid and if so answering them? or do you want a bunch of jiberish?
Reply:I started to put semicolons at the end of my English sentences because I'm so used to it;
Reply:1) every c++ program has a specific syntax that the comp understands or you can say that designers have designed in that way.it is the same as when you end a sentence you put a full stop you cant question why we do it right.





2)if we do not declare the variables before had how the comp would know what data type it has.





3)the c++ takes a space also as a character.





4)c++ has some inbuilt functions like iostream.h,conio.h when we use commands like getch() we need these functions.





5)a variable name:


-%26gt;must begin with a letter or underscore


-%26gt;may contain alphabets and underscore symbol


-%26gt;must not contain any other character or symbol


-%26gt;may be of any length


-%26gt;must not be a keyword


-%26gt;must contain a type specifier preceding a variable name.
Reply:Thats hard.

daisy

No comments:

Post a Comment