Friday, May 21, 2010

C? what does scanf does? Wich one is used for hardware? c or c++?

what is the difference between c and c++





wich one is easier??





wich one is used more often?

C? what does scanf does? Wich one is used for hardware? c or c++?
First, scanf is used to read value the user types at the command prompt. For example:





int someNumber;


scanf ("%d",%26amp;someNumber);





would wait for the user to type something and press [ENTER]. It would then try to parse the text that was typed into an integer value and place that value in the "someNumber" variable, assuming they typed a valid number.





Either language can be used to interact with hardware, however I myself have never tried to do any sort of embeded systems programing -- I mean all I've worked with is writing relatively simple programs that run on Windows.





C++ adds Object Oriented abilities to the C programming language while still aiming for 100% backwards-compatability with C. And from what I've read it comes pretty close to 100%, however I've never really tried to compile any even remotely complex C program on a C++ compiler.





Anything you learn to do in C will definitely be helpful in learning C++, so if you're looking for what is easiest, you could start by learning C and then moving on to C++.





From what I could find on the Internet, C is more widely used than C++ , but that's probably hard to gauge.
Reply:c++ is object oriented. C can be considered as an earlier version and also a subset of C++. So C is easier. Onhardware C is generaly used.
Reply:In C language (and it can be used in C++) the scanf function is used to accept input from a device, like a keyboard. For example:


char string[80];


scanf("%s", string);


This code will pause the program and wait for the user to enter a series of characters followed by the enter key. In C++ the same thing is usually done using the "cin" function. Like:


cin %26gt;%26gt; string;


The scanf will work in C++ and C. The cin will only work in C++.





C was a language developed for procedural coding, though you can produce something like OO code in C. C++ was designed to be more Object Oriented than C, but it doesn't enforce OO design techniques. Neither one is really better for hardware.





Currently, C++ is preferred over C due to it's OO capacity, but it is not necessarily easier. If you understand OO concepts, C++ would not be more difficult than C. If you don't understand OO, I would probably advise you to learn a little bit about it and use C++.





I'm not a C++ or OO bigot. I'm just expressing my opinion based on my experiences. Good luck!
Reply:Your title doesn't make a lot of sense but I will try to answer your question. scanf() is a function in the stdio.h library that scans input from standard in (usually keyboard).





C is a subset of C++. C++ includes all the libraries of C. The difference is that C++ includes Object Oriented Design (classes), C does not.





Which one is easier is a very subjective question. I learned C before I learned C++, and I personally would recommend C first. The main reason is that in C++ a lot of things are done behind the scenes and you wont have a thorough understanding of C++ without C.





Both C and C++ are used extensively. For anything where speed is key unless you understand C++ well, C is a good choice. Otherwise C++ is usually easier.


No comments:

Post a Comment