Hi, another question from someone who is interested in learning more about C/C++. My question is that everyone says C/C++ is more powerful than many other languges e.g Visual basic but why is it more powerful. Is it because of the pointers ? As far as my knowledge goes they only grab and return the address of a variable and then using that address you can link another variable to your already stored variable but how is this useful, I have read other forums and people usually reply saying it is helpful in optimising the code and reduces the memory consumption, true but nowadays we usually have high speed Rams with atleast 2 GB and multiple core processors. For applications like an instant messenger, wordpads, web browsers I dont think it is needed. Obviously in game development its different. So why are pointers so important give me an example where the pointers play an extremely important part ? whats the point of pointers when I can just copy a value from another variable. I am interested in programming embedded systems, PIC, AVR. People say you need pointers in programming those systems, how are pointers used and what do they do in programming embedded systems ?

Also people say C/C++ are multiplatform but then any compiler for any language converts the code written by human into machine code i.e "01010101" then why is it that visual basic is not compatible with mac or linux once compiled ?? I just dont understand how C/C++ is so much more "powerful" what sort of powers does it give you ?

Maybe you should consider that most computer languages use C as its interface to the outside world. Why would a language so foreign to C use C as its interface? Well maybe C is a general representation of the machine...I'll probably get nailed for this general/simple statement.

C/C++ offers several advantages:

1) some free compilers, as well as competing commercial compilers, and a huge base of libraries. VB has none of these, that I know of.

2) a huge installed base of trained C/C++ programmers

3) there are a wide variety of compilers. One or more, for almost any device you can think of. VB has very few.

4) a C type program can be much smaller than a VB program, after compiling.

5) lots of good tools for the programmer in C/C++. Very few for VB.

Many data structures require the use of pointers to create them: linked lists, binary trees, circular buffers, etc. I don't believe there is any way to create these, in VB. (in some cases you can mimic them with arrays, but that's not the same)

In some specific tests, VB is probably just as fast as C/C++, before optimization. When you want/need more performance, you need the low level expertise that VB doesn't offer as a language. Indeed, mainframe programmers STILL rewrite critical portions of their application code, in optimized assembly code. For them, anything that isn't first rate in speed, is not going to be useful. If they had the time, they'd code up the whole program in assembly. Of course, that's impossible, but you get the idea - optimizing software is a BIG deal for their bottom line. VB is simply of no use for them.

VB is a fine language, but it's not supported enough, and has none of the professional tools that I'd want to use, either. If you wanted to run your VB program on a profiler, or see the assembly output of the compiler or interpreter, you'd be SOL I believe.

Also people say C/C++ are multiplatform but then any compiler for any language converts the code written by human into machine code i.e "01010101" then why is it that visual basic is not compatible with mac or linux once compiled ?? I just dont understand how C/C++ is so much more "powerful" what sort of powers does it give you ?

machine code can be different from computer to computer, and all libraries are not on every OS, for example, you cannot implement a windows gui on a unix or mac os computer. So something compiled in windows will not necessarily work in mac os, or in a unix-based os

most computer languages use C as its interface to the outside world.

Not to steal some of the spotlight from the thread, but I'm confused by what you mean when you say this.

Good points Adak.

see the assembly output of the compiler or interpreter

The OP wasn't specific, but with VB.NET there are a lot more possibilities for this kind of thing. Any of the .NET languages (C# and F# included) are translated into Intermediate Language (MSIL http://msdn.microsoft.com/en-us/library/c5tkafs1(v=vs.71).aspx), which means anything you can do in C# you can do in VB these days. MSIL is not quite assembly, but gets you one step closer to the machine. You can hand tune your MSIL even in VB, I believe.

My 0.02, although you didn't say you were trying to choose between these options, if you were in a position to, I would say instead of VB, learn C# in addition to one or both of C and C++. Most of the skills from C/C++ will transfer (data structures, looping, etc.). That way you'll be able to do .NET without having to worry about VB.

My question is that everyone says C/C++ is more powerful than many other languges e.g Visual basic but why is it more powerful.

Not everyone. Making such a claim is misleading because the definition of "powerful" hasn't been nailed down. Yes, C and C++ are both powerful languages, but other general purpose languages are also powerful. More powerful implies that the two languages being compared are in direct competition for all possible measures, which is certainly not the case with C/C++ and Visual Basic and is rarely the case in general.

As an example, Visual Basic is typically the language of choice[1] for developing GUIs on a Windows platform because it excels at that. Visual Basic is also surprisingly powerful in terms of Windows programming if you know what you're doing. But historically VB has been slower, so a common choice was to use VB at the front end and C++ at the back end. The two complement each other, and aren't in direct competition. A wise developer chooses the best tool for the given task.

Is it because of the pointers?

There's no single feature that makes or breaks a language as being "powerful". But pointers are indeed fundamental to the point where if one can't properly understand them, becoming truly proficient at C/C++ is impossible.

nowadays we usually have high speed Rams with atleast 2 GB and multiple core processors

More RAM and faster CPUs are a godsend for people who can't write efficient code. But keep in mind that in a multitasking system your software isn't the only thing running. Even in the presence of plenty of memory and processing power, it's still a good idea to be mindful of efficiency.

So why are pointers so important give me an example where the pointers play an extremely important part?

Any kind of linked data structure will be gimped if you have to use indexing (the alternative to pointer links) in a statically sized array. Further, dynamic allocation essentially requires some form of handle type (ie. a pointer).

why is it that visual basic is not compatible with mac or linux once compiled ??

The executable file format is different. Visual Basic builds into a Windows specific PE-COFF format, which simply isn't recognized by Unix or Linux without a compatibility layer like Wine. Yes, ultimately all code gets interpreted as binary, but there are many layers of potential incompatibility above that which makes writing portable software difficult.


[1] That's not really true these days, as there are other options for rapid development of GUIs, but that's an irrelevant nit for the topic at hand.

Not to steal some of the spotlight from the thread, but I'm confused by what you mean when you say this.

Most languages have facilities that allow you to extend the language..These features are usually implemented in C. Python is a good example of this.

Another thing that hasn't been mentioned yet: You know that in VB, when you pass a variable BYREF, you are passing the address of the variable - that's a pointer. Why do you do that? Because it's an order of magnitude faster than passing a copy of the data.

Any time you're going to start writing a program you have to make several choices. One of those is "How much time do I have to write this?" vs "How big is it going to be and how much memory is it going to use?"

I, personally, crave efficiency. If I'm in a hurry, I'll use AutoIt (www.autoitscript.com), a Basic-like language, which makes it ridiculously easy to create a Windows program. Later, when I have more time, I'll then convert that to C.

Why do you do that? Because it's an order of magnitude faster than passing a copy of the data.

That's an exaggeration and an incorrect absolute statement. Passing by pointer requires subsequent dereferencing within the function, which incurs a performance hit. If the cost of copying your data doesn't outweigh the cost of using a pointer, there won't be any benefit to it. That's why primitive scalar objects generally aren't passed by pointer except when they need to be modified. They're not large enough to justify another level of indirection.

True, I was not referring to scalar objects. I was trying to use a simple analogy that the OP might understand. The (larger) size of the data was implied since I was talking about efficiency.

ok the thing is I am new to C, so what is a data structure, do you mean struct{} ? or classes in C++ ? I was actually talking about VB.net. Ok RDSchaefer so if I have a variable that just got filled up with lots of data from an SQL database field it would be better to use a pointer to read that variable rather than copying it to another variable ?? cheers.

Also would pointers help improve the efficiency and reduce memory occupied on a PIC microcontroller programmed with C ?? are there any other uses of Pointers ?

Computers and peripherals are address reliant - they must have them, or no go. It's no accident that all the operating systems (CPM, DOS, Linux, Windows, etc.), use addresses extensively. Pointers hold addresses, and are the only variables who do hold addresses.

Whether the language in question allows pointers or not for the user, you can be sure that the language itself is using them, to interface with the operating system or hardware.

How much pointers being used by the language, would help any particular peripheral device, depends on the system, the peripheral, the operating system, and what the program is doing.

Although pointers are powerful, they can also make code unbelievably difficult to understand and modify or debug, if over-used.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.