Tell one difference which is in C and not in C++. Can we pass arguments in main() Difference between static and constant variable.

This question is related to TCS Interview

Questions by harinisathiyamurthy   answers by harinisathiyamurthy

Editorial / Best Answer

hrs1129  

  • Member Since May-2008 | May 28th, 2008


yes we can pass arguments if we pass argument ir would become commandline argument.
 eventhough static and constant variable are common for alla objects the value of static variable can be increased in time being but it cannot be increased in constant variable

Showing Answers 1 - 61 of 61 Answers

hrs1129

  • May 28th, 2008
 

yes we can pass arguments if we pass argument ir would become commandline argument.
 eventhough static and constant variable are common for alla objects the value of static variable can be increased in time being but it cannot be increased in constant variable

one thing in c but not present in c++
=============================
in C we need not to mention the header files for using the built-in functions.

but, in C++ we must mention the header file for same purpose.

this is the very basic difference between these two languages

and when MAIN() have arguments this means that...

when we start program from command promt we can pass starting arguments to the program.
these r nothing but the values which the programmer things that must be there when program starts execution.

C is a procedure oriented language (emphasis on procedure or algorithms)

C++ is object oriented (emphasis on data)

In C keywords new and delete are not available(memory management),in C++ its otherwise
In C we use multiline comments/* */,C++ single line//
 
C does not provide default arguments while C++ does.

Static variables change their values with the iteration while the while does not change when constant variables are used.


  Was this answer useful?  Yes

Yes we can pass argument through main function.
For example 

 void main(int arg,char d[5])
// arg count the number of argument (currently no. of argument is 2)
{
 if(arg<1)      //2<1
{
cout<< "hello";
exit(0);
}
for(int i=0;i<arg;i++)
{cout<<"test-msg";}   //output will be test-msg

Difference:
1. C is procedural language and C++ is object oriented.
2. C works on top down approach & C++ on bottom up approach.

saurabh1341

  • Oct 22nd, 2010
 

1. C has malloc and calloc for dynamic allocation of memory, while C++ uses "new"

2. Yes we can pass.. it is called command-line agument

3. Static can be changed, constant cannot be

  Was this answer useful?  Yes

  1. C is a subest of C++
  2. C provide action/structure/function oriented programming C++ provides object oriented programming with features such as : abstraction, encapsulation, polymorphism, inheritance.
  3. C++ is a strong type checking langugae as compared to c. So many programs which would complile without any warning or error in c compiler results in many warning and error in C++ compiler.
  4. C++ supports sophisticated error handling using the Exception Handling Mechanism.

  Was this answer useful?  Yes

C++ provide data hiding inhertance and many other features


We can pass argument in main i.e command line argument

Static variable hold last hnage value throughout the program but not const

  Was this answer useful?  Yes

C++ is more secure than C. C++ is object oriented where as C++ is not. C have got Top to down approach where as C++ has got bottom up approach.
 
Inheritance & polymorphism is available in C++ whereas they are not in C.

  Was this answer useful?  Yes

vivek

  • Aug 19th, 2011
 

no we can't pass the argument in c in main function,but we can in c++.

  Was this answer useful?  Yes

akhilesh

  • Aug 22nd, 2011
 

In c declaration of variables are allowed only at the Beginning of the method i.e. just after '{' .
but in c++ we can declare anywhere. :)

  Was this answer useful?  Yes

One thing allowed by C that is *not* allowed by C++ is for main() to be called from within the program itself. IOW, in C, it's possible for main() to be recursive.
The main() function in both C and C++ can accept arguments, with the following caveats:
1. In both languages, the standard signatures for main accept either 0 arguments (in main(void) for C, int main() for C++) or two arguments, the first being an integer designating the number of command-line parameters, and the second being a pointer to the command-line arguments themselves (int main(int argc, char **argv)).
2. The C language standard explicitly allows an implementation to define alternate signatures for main() - some implementations allow a third parameter similar to argv commonly named envp (basically, a vector of environment variable values).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions