Páginas

domingo, 1 de diciembre de 2013

Learning C++ Pointers for REAL Dummies

Introduction

Hello and welcome to "Learning C++ Pointers for REAL Dummies." This website was created by Paul DiLorenzo to fill the void of an easy understanding learning module for pointers.
Here are some rave reviews from people around the world:
  • "GOOD JOB with learning C++ pointers for dummies. Because of you I hope to get a 10 (that means A) at programming." Dan
  • "Sir, your tutorial on pointers is a masterpiece, I think you should continue writing more topics on C++." Mayur Jethwa

Pointers are a very difficult and troublesome area for most C++ programmers, beginners and intermediate alike. Most questions pop up about their use and why we even need them. I hope this website helps answer these questions for you and demystify the C++ pointer.
To understand pointers we have to understand how variables are stored. Variables are stored in memory cells inside the computer's memory. The computer's memory is made up of consecutive memory cells, a byte long, each with a unique address.
But we are not going to think in those terms. We are going to believe that computer memory is made up of a bunch of houses on one very long street. Thus, each house is a memory cell. Now, there must be a way for us to find this house. Well, in each house someone lives there. This person of course has a name and this will be our variable identifier. For example:
int paul;
This will put paul into a vacant house, of size int, somewhere along the street. We do not decide where paul will live. This is done by the operating system and the compiler at runtime. In a later section, we will discuss how to get paul to tell us where his house is.
Currently, paul does not have anything stored in his house. But, we all know that wouldn't be any fun to not store anything. So, each house can of course store a value. Continuing from above:
paul = 25;
This will store the value 25 into paul's house.
One last thing before we move into other topics. Let us remember thatpaul's house is a unique number in memory. In addition, if paul's house was numbered 1234 we know that his house is between houses 1233 and 1235. This is a very important concept for later sections.
This learning module is broken up into seven parts:
  1. Where do you live ( & ) - Explains what the address operator (&) is and how it is used
  2. What you got in your house (*) - Explains that the reference operator (*) is and how it is used
  3. Don't point, it's rude! - Explains how to declare variables that are pointers
  4. I am pointing here! Where are you pointing? - Explains how to initialize a pointer
  5. How do I point to the neighbor? - Explains how to move a pointer from one house to the next
  6. You guys are brothers? - Explains the relationship between arrays and pointers
  7. Beam me up Scotty, multiple times!!! - Explains how pointers can point to other pointers

Simple Array Tutorial in C++:

In this tutorial, I show you some basics about using Arrays in C++. Arrays are very simple when it comes to the basics and if you know it, you can get a lot done in a shorter period of time. The video takes you through some basics as well as shows you how it works as well as how to input and output data for arrays on the screen.

I will try to make another tutorial for Arrays where I go into using multiple array variables and output everything with and without sorting. It's very interesting and I hope you get to see it soon.

I hope you enjoy the video and if you have any requests feel free to let me know. Thanks for watching ! Thanks for watching and thanks for your supportand remember to subscribe!


lunes, 25 de noviembre de 2013

Friday November 22, 2013

Today was our finall day of labs and we had to send our fives last programs. To me, they were the most dificult of all. I spent a lot of time working on the problem four. That problem was the most I liked of all, because it was very similar to the software that the library utilizes. I do not had the time to finish all fives problems but at least I could send three of them.
Wednesday November 20, 2013

Today we have almost 3 hours of lectures and some of the things that we discuss were the final of chapter 8 and started discussing chapter nine. We discuss in chapter eigth about vectors that are like arrays that can change size, how can we declare it and how we can use them in our sourcescodes. But in order to use them we need to include the library of vectors that is  #include <vector>. We ended the chapter discusing about controlling vector capacity and later on we starter discusing the basics about pointers. How can we utilizes, what is a pointer, what is the purpose of a pointer and how we can trackt it alongside with our code.

Friday November 15, 2013

One of the things we discuss in class today was the ignore. That is a member of the istream class and it can be utilize to read and eliminated all characters. But it takes two arguments: The first oe is the maximum number of characters to discard and the second is the character that stops reading and discarding. Also I learn that comparison operators also can work with string objects  = = and  returns true if two string objects contain the same characters in the same order. We can also transforms strings in c++ to c-trings.

Wednesday November 13, 2013

We started to see the that the variables of type string can be assigned with the = operator to assigned them a string of words. But the constructor initializes the string to the empty string if you donot initialize the variable when you declare it. We also recall that the cin skips the whitespace   to find what it is to read then stops reading and the versions of getline stop reading at the end of line marker. Later all we ended with the lacture and I started workin with my lab 7.



Microsoft updates C++ compiler

Update lets Visual Studio support some aspects of C++11

By Joab Jackson
November 5, 2012 12:15 PM ET
IDG News Service - Microsoft is updating its C++ compiler for its Visual Studio 12 integrated development environment, or IDE, so that Windows application developers can use parts of the latest version of the programming language, C++11.
Friday afternoon, Herb Sutter, secretary of the ISO/ANSI C++ Standards Committee as well as a Microsoft platform evangelist, announced the release of the new batch compiler during a talk about the future of the language at the Microsoft Build conference, held in Redmond, Washington,
The company has released a compiler CTP (community technology preview) that supports some of the features in the latest C++, including variadic templates, uniform initialization and initializer_lists, delegating constructors, raw string literals, explicit conversion operators and default template arguments for function templates.
The release is the first of what will be a series of "out-of-band" releases, which periodically update the Visual Studio IDE with new features in between major releases, Sutter said. Microsoft will release additional C++ functionality in early 2013 in future out-of-band updates, Sutter said.
The CTP requires Microsoft Visual Studio 12 to run, though it can be run in a free version of the IDE, Desktop Express. Visual Studio 2012 built-in tools, such as Intellisense, debugger and static analysis do not yet support the new C++ features.
"We updated the batch compiler [but] the standard library has not been yet updated, so some of the new features that the standard library could use haven't been lit up yet," Sutter said. "That's just for the CTP. When we ship it, all those features will be in place."
Sutter said that while Microsoft CTPs tend to be pretty stable, it would not be advisable to use the compiler to produce production-ready programs.
As Sutter noted during his talk, there has been a lot of activity around the programming language of late. Microsoft, Intel, Google, IBM and other members of the C++ Committee have formed the Standard C++ Foundation, which will provide educational materials and encourage the correct use of C++ across different compilers.
The standard group has also commenced work on the next generation of the C++ language, C++17, due in 2017.
Developed in Bjarne Stroustrup in 1979, C++ brought object oriented features to the C programming language. It remains one of the most widely used programming languages, and is often used for large scale applications where performance is a critical factor. "We are built on C++, just as the whole industry runs on C and C++," Sutter said, referring to how much of Microsoft's latest operating systems, Windows 8 and Windows RT, was written in C++.
Joab Jackson covers enterprise software and general technology breaking news for The IDG News Service. Follow Joab on Twitter at @Joab_Jackson. Joab's e-mail address is Joab_Jackson@idg.com

  • Low Level Languages:-
1. It is close to Machine language.
2. It is difficult to learn and use.
3. It is machine dependent
4. It does not provide built in functions.
5. Program written in low level language is faster in execution.
6. Deep knowledge of hardware is required to learn and use low level languages.
7. There are few programmers that can write programs in low level languages.
8. It is difficult to trace out errors in the programs written in low level language.
9. Low level languages are not commonly used.
10. The program statement written in low level language is very lengthy.
  • High Level Languages:- 
1. It is close to human language.
2. It is easy to learn and use.
3. It is not machine dependent.
4. It provides large number of built in functions.
5. Program written in high level language is slower in execution.
6. No deep knowledge is required to learn and use high level language.
7. There are many programmers that can write programs in high level language.
8. It is easy t trace out errors in the program written in high level language.
9. High level languages are commonly used.
10. The program statement written in high level language is very short.

Lower Level Languages and Higher Level Languages

Generally speaking higher level programming languages are closer to human spoken languages and lower level programming languages are closer to machine code, or binary. However this classification might not always be so clear. C++ is one language that some might argue challenge this programming language stereo type. C++ is a programming language that has all the features that one would expect from a higher level language such as an easy to read syntax, object oriented programming and extensive collections of libraries to add to the language's capabilities but also has other features that are not commonly found in higher level languages such as memory management, user defined operator overloading, six different integer datatypes and a plethora of compilers to choose from. As a result many refer to C++ as a mid-level programming language. 
For Processing this distinction is currently not so difficult to make. Processing is a high level language, meaning it has an easy to read syntax, supports modern day programming concepts such as Object Oriented Programming, has it's own IDE (Integrated Development Environment something we will become more familiar with throughout this guide) and fundamentally it abstracts a lot of machine specific interactions for us making the code more readable for humans.
However, it's worth considering that the terms “higher” and “lower” level programming languages are relative to the time period in which they are used. For example when the programming language C (that C++ is based on) was first introduced in the early 1970's it was considered to be a high level language as it supported such features as expression evaluation and datatyping, both of which are programming concepts common to most modern day programming languages. As technology progresses, new concepts become common place and rapidly replace older more cumbersome programming designs, till we get to the point where there are far less people that would refer to an older language such as C as being a high level language and a lot more people that would refer to it as a low level language, lacking modern abstractions and less direct hardware interactions. Processing might one day, also be subjected to such a topic of discussion.

Following is the C version of a “Hello World” Program:

#include <stdio.h>
int main(void)
{
    printf("hello, world\n");
    return 0;
}

The level of abstraction that is needed in order for a language to qualify as a higher level programming language does not come without it's penalties. Lower level languages, because they are conceptually closer to machine code are considered to produce more efficient machine readable code, of course this is largely dependent on the programmer creating the code. As mentioned before the greater the level of abstraction of the code, the more stress that is placed on the machine interpreting the code, and subsequently more system resources are required. As a result of this cycle higher level programming languages generally cannot run on systems where resources are limited. Initially, this might not seem like such a big issue to you, but have you ever considered the amount of technology running on limited resources like a television, fridge, GPS, mobile phone, remote-controlled air-conditioner, electronic toys, media players and the list goes on...? In fact if you were to think about it there are not many devices like computer workstations, laptops or computer servers that are designed to have their resources, available to the software that runs on these machines, extended. Yet, even these machines have their limitations.
Ultimately software, whether it is designed with a high level or low level programming language, should always take into consideration the possible limitations of available system resources.

Avoiding Pointer Problems in C++

Part of the Beginning Programming with C++ For Dummies Cheat Sheet

In C++, a pointer is a variable that contains the address of another variable in the computer's internal memory. Use these steps to avoid problems with pointers in C++:
  1. Initialize pointers when declared.
    Never leave pointer variables uninitialized - things wouldn't be too bad if uninitialized pointers always contained random values - the vast majority of random values are illegal pointer values and will cause the program to crash as soon as they are used. The problem is that uninitialized variables tend to take on the value of other, previously used pointer variables. These problems are very difficult to debug.
    If you don't know what else to initialize a pointer to, initialize it to zero. Zero is guaranteed to be an illegal address.
  2. Zero pointers out after you use them.
    Similarly, always zero a pointer variable once the pointer is no longer valid. This is particularly the case when you return a block of memory to the heap using delete; always zero the pointer after returning heap memory.
  3. Allocate memory from the heap and return it to the heap at the same "level" to avoid memory leaks.
    Always try to return a memory block to the heap at the same level of abstraction as you allocated it. This generally means trying to delete the memory at the same level of function calls.
  4. Catch an exception to delete memory when necessary.
    Don't forget that an exception can occur at almost any time. If you intend to catch the exception and continue operating (as opposed to letting the program crash), make sure that you catch the exception and return any memory blocks to the heap before the pointers that point to them go out of scope and the memory is lost.
  5. Make sure that the types match exactly.
    Always make sure that the types of pointers match the required type. Don't recast a pointer without some specific reason. Consider the following:
    void fn(int* p);
    void myFunc()
    {
        char c = 'a';
        char* pC = &c;
        fn((int*)pC);
    }
    The above function compiles without complaint since the character pointer pC has been recast to an int* to match the declaration of fn(int*); however, this program will almost surely not work. The function fn() is expecting a pointer to a full 32-bit integer and not some rinky-dink 8 bit char. These types of problems are very difficult to sort out.

The Usual C++ Header Files

Part of the C++ All-In-One For Dummies Cheat Sheet

In C++, a header file holds forward declarations of identifiers. Here are some of the most common C++ header files that you’ll be using, along with their correct spellings. These aren’t by any means all of them, but they are the most common:
  • Include <string> if you’re going to be using the string class.
  • Include <iostream> when you want to use cout and cin.
  • Include <fstream> when you want to read or write files.
  • Include <iomanip> if you want advanced manipulator usage in your streams.
  • Include <stdlib.h> for general operations, including system(“PAUSE”).

The Ten Most Common C++ Mistakes

Part of the C++ All-In-One For Dummies Cheat Sheet

Although many C++ programmers take measures to prevent bugs, mistakes still slip through. This list of the ten most common mistakes while writing C++ code can help both new and veteran programmers:
  1. You forgot to declare the variable.
  2. You used the wrong uppercase and lowercase letters; for example, you typed Main when you meant main.
  3. You used one equal sign (=) when you were supposed to use two (==), either in an ifstatement or in a for loop.
  4. You forgot #include <iostream> or using namespace std;.
  5. You dropped the laptop in the swimming pool.
  6. You forgot to call new and just started using the pointer anyway.
  7. You forgot the word public: in your classes so everything turned up private.
  8. You let the dog eat the remote.
  9. You forgot to type the parentheses when calling a function that takes no parameters.
  10. You forgot a semicolon, probably at the end of a class declaration.

Should Developers Start Learning C++?

by Jonathan Allen on Dec 06, 2012 | 9 Discuss
With the introduction of C++ 11 and C++ CX there has been a lot of renewed interest in the language. And a lot of developers, especially Windows developers, are wondering if they should set aside C# and Java in favor of it. John Sonmez argues no.
In his article titled Why C++ Is Not ‘Back’, John Sonmez argues that there are only three reasons to use C++:
  • You absolutely need to ink out every bit of performance possible out of your software and you would like to do that with a language that will support OO abstractions.
  • You are writing code which will directly interface with raw hardware.  (Example: you are writing a low level driver.)
  • Memory control and timing is of absolute importance, so you must have completely deterministic behavior in your system and the ability to manually manage memory.  (Think real time embedded operating system controlling a moving piece of machinery.)
Herb Sutter, who has heavily praised this article for offering a “a thoughtful hype-free opinion” adds to the list:
  • Servicing, which is harder when you depend on a runtime.
  • Testing, since you lose the ability to test your entire application (compare doing all-static or mostly-static linking with having your application often be compiled/jitted for the first time on an end user’s machine).
One of the reasons that John Sonmez offers against learning C++ is the sheer complexity of the language. Even though C++ 11 has made development easier, it doesn’t excuse the programmer from learning all of the old ways of writing C++ code. “You will encounter C++ code from 20 years ago and it will look like a different language entirely.” To reinforce his point he posted the 36 questions he asked candidates for a C++ developer position. Here are a couple of examples,
1. How many ways are there to initialize a primitive data type in C++ and what are they?
12. What is a copy constructor and when is it used, especially in comparison to the equal operator.
16. When is it and when is it not a good idea to return a value by reference in C++?
33. Why should you never throw an exception in a destructor?
Another argument against C++ is that “programming languages really need to get simpler and increase the level of abstraction not reduce it.” He continues,
There will always be a need for low level code, but a majority of the code that we write today is at a much higher level.
I first jumped off the C++ ship many years ago when I finally could no longer make the argument that I could develop apps faster in C++ than C#.
I held out for a long time trying to believe that all the investment I had made in C++ was not lost, but it turned out that C# simplified things to such a great degree that the extra power C++ gave me was not worth the extra responsibility.
John Sonmez concludes by saying that learning C++ is still useful for understanding how computers work in general, “but I don’t think it is going to make a comeback any time soon, and that is a good thing.”
To this Alo adds,
I started out on C++ and spent the first four years of my career exclusively on C++. That experience has been extremely valuable for me down the line because – as you pointed out – once you learn C++ to an adequate level, you can pick up any other language really fast and you’ve developed a deeper understanding of how software works on a lower level – a knowledge that’s much harder to acquire when starting out at higher-level languages; I’ve always frowned upon the idea of starting programmers out on Java for that very reason.
Richard Dunks counters with,
I think C++ is unhelpful for use in first semester introduction to programming classes and in teaching data structures, you have to spend so much time on the implementation, the students often lose sight of the structure they’re trying to replicate. I’m glad I’ve gained the proficiency in C++, but I don’t think it’s worth the cost and definitely not a one-size fits all instructional language.
Stephen Cleary offers a comment on reusability,
I’m a former C++ master who became a C# developer a few years ago due to marketplace pressures. I am CERTAINLY more productive in C#, but it’s simply not possible to reach the same level of code reuse as you can with C++ templates.
The classic example is the triumvirate of containers, iterators, and algorithms. In C++, you can create one algorithm that will work with any container and adjust itself at compile time to take advantage of random access if necessary. Try doing that in C#. And I’m not talking about the “new C++” here, either; C++ permitted greater code reuse in 1998 than C# does today.
And in regards to performance, Herb Sutter offers this bit of advice,
In any language, if you are serious about performance you will be using arrays a lot (not “always,” just “a lot”). Some languages make that easier and give you much better control over layout in general and arrays in particular, while other languages/environments make it harder (possible! but harder) and you have to “opt out” or “work against” the language’s/runtime’s strong preference for pointer-chasing node-based data structures.
In additional to numerous high quality comments on Herb Sutter and John Sonmez’s respective blogs, there is much to be learned from Programming and Coding subgroups of Reddit.

Microsoft Visual Studio 2013 Review

I admit it: I've been an avid Visual Studio user since the IDE's introduction. The original product represented a major milestone for Microsoft because it brought together for the first time the company's collection of languages under one umbrella. Essentially, it became the Microsoft Office suite for developers. Nearly 15 years later, Visual Studio is the default development environment for developing Windows applications, ranging from traditional WinForms to the latest WinRT creations.

What's New?

Visual Studio 2013 (VS2013) is another release that adds important new technologies that I'll touch upon shortly. Among the most visible are some cosmetic changes, such as more than 400 modified icons that update the UI to a more colorful Windows 8 look. Others changes are nifty code editing efficiencies that appeared first in Visual Studio Power Tools add-ons, but are now officially integrated and supported. For example, editing improvements such as in-line code navigation and automatic bracket completion. But my favorite code editing improvement is the new scrollbar behavior: "Bar mode" is the traditional scrollbar operation, while "map mode" is something seen only in a few editors such as Sublime Text. In the VS2013 implementation, a miniaturized representation of the entire file being edited appears in a thin window down the right side of the edit panel (Figure 1). The map highlights the section of code that your cursor is located in and allows you to zoom in, thereby facilitating navigation in a large source file.
Figure 1: The new Map Bar feature that appears on the right of code-editing pages.
Other code enhancements include the in-line Peek Definition view from the Go To Definition context-sensitive menu option, automatic bracket completion, and the ability to move blocks of code via the a keyboard shortcut (which can be changed in the Tools -> Options -> Environment -> Keyboard dialog). Check out Microsoft's Visual Studio tips and tricks page for other useful keyboard shortcuts.
For Web development, the editor has been updated to support the latest HTML5 and CSS tags, and it is IntelliSense-enabled. And seeing how audio and video file elements dragged into the code window are wrapped inside appropriate HTML5 tag structures is a great help.
Another long overdue feature I was glad to see is VS2013's ability to edit-and-continue native 64-bit application debugging sessions. Considering that the majority of new enterprise applications are 64-bit, this improvement finally brings the 64-bit development experience to parity with the 32-bit step-debugging tools we have come to expect in any modern IDE.
On the code management front, the latest Team Foundation Server is supported along with the addition of the Git distributed SCM that has all but replaced Subversion as the default open-source code-management solution. And very helpful code changeset pop-ups embedded within the code quickly show exactly who wrote what (Figure 2).
Figure 2: Git support includes pop-up windows that show who did what.
There are a host of Windows 8.1-specific support enhancements as well, especially in the development of XAML-centric applications. For example, the XAML editor now supports a comprehensive set of IntelliSense options ranging from data and template binding, to finding references and Go To Definitions, to better integration with Microsoft's Azure Mobile Services for cloud-based hosting. Microsoft's standalone Blend designer tool also includes better styling and timeline capabilities to help speed up XAML interface development. And VS2013 now provides XAML performance analyzers to measure responsiveness, energy consumption, memory, and other metrics. They are especially helpful, though, in diagnosing delays in responses.
Figure 3: VS2013 offers performance analysis for XAML UI Responsiveness among other metrics.
Visual C++ has also received some well-deserved attention in VS2013, including better support for the C++11 specification (constructor delegation, explicit conversion operators, and variadic templates to name a few). A new Profile Guided Optimization leverages VS2013's improved profiling tools by allowing you to refine your C++ program based on visualizing the hotter and colder code paths.

Cloud And Web

VS2013 also supports Office 365 Cloud Business application development. With rumors swirling that a fully implemented Microsoft Office suite will one day make it to Android and iOS platforms, this technology has tantalizing possibilities for easy Office-centric ALM across a variety of mobile platforms.
Web development is another area where VS2013 has made ample improvements. ASP.NET developers will be pleased to discover that they can comfortably mix and match whatever framework they prefer (MVC, Web API, WebForms) in the same project. Gone are they days of segregating Web applications based on framework boundaries. Now, all of these technologies can operate happily together under the same umbrella.
Another nifty feature that will elicit a nod of satisfaction from Web developers is the new Browser Link capability. Browser Link keeps the latest browsers such as Internet Explorer, Chrome, and Firefox in sync with your code, showing design and behavior code changes in real-time. You can finally say goodbye to unnecessary button clicks, keypresses, and manual page refreshes.
VS2013 also expands support for new languages like TypeScript. TypeScript compiles down to JavaScript, but makes working with complex JavaScript-related operations far more manageable since TypeScript supports the full compliment of classes, interfaces, and modules that OOP programmers have come to rely on. VS2013 works with TypeScript just like it does with other languages by providing full support for code navigation and refactoring, statement auto-completion, and the like. And TypeScript can use popular JavaScript libraries such as Bootstrap and jQuery.