Sunday, 6 October 2013
0
Sunday, 6 October 2013
Unknown
Read More
Pointers
Pointers
Pointers can be confusing, and at times, you may wonder why you would ever want to use them. The truth is, they can make some things much easier. For example, using pointers is one way to have a function modify a variable passed to it. It is also possible to use pointers to dynamically allocate memory allowing certain programming techniques, such as linked lists and resizable arrays. Pointers are what they sound like...pointers. They point to locations in memory. Picture a big jar that holds the location of another jar. In the other jar holds a piece of paper with the number 12 written on it. The jar with the 12 is an integer, and the jar with the memory address of the 12 is a pointer.
Pointer syntax can also be confusing, because pointers can both give the memory location and give the actual value stored in that same location. When a pointer is declared, the syntax is this: variable_type *name; Notice the *. This is the key to declaring a pointer, if you use it before the variable name, it will declare the variable to be a pointer.
As I have said, there are two ways to use the pointer to access information about the memory address it points to. It is possible to have it give the actual address to another variable, or to pass it into a function. To do so, simply use the name of the pointer without the *. However, to access the actual memory location, use the *. The technical name for this doing this is dereferencing.
In order to have a pointer actually point to another variable it is necessary to have the memory address of that variable also. To get the memory address of the variable, put the & sign in front of the variable name. This makes it give its address. This is called the address operator, because it returns the memory address.
For example:
Code:
?#?include? <iostream>
using namespace std;
int main()
{
int x; // A normal integer
int *p; // A pointer to an integer
p = &x; // Read it, "assign the address of x to p"
cin>> x; // Put a value in x, we could also use *p here
cin.ignore();
cout<< *p <<"\n"; // Note the use of the * to get the value
cin.get();
}
The cout outputs the value in x. Why is that? Well, look at the code. The integer is called x. A pointer to an integer is then defined as p. Then it stores the memory location of x in pointer by using the address operator (&). If you wish, you can think of it as if the jar that had the integer had a ampersand in it then it would output its name (in pointers, the memory address) Then the user inputs the value for x. Then the cout uses the * to put the value stored in the memory location of pointer. If the jar with the name of the other jar in it had a * in front of it would give the value stored in the jar with the same name as the one in the jar with the name. It is not too hard, the * gives the value in the location. The unasterisked gives the memory location.
Notice that in the above example, pointer is initialized to point to a specific memory address before it is used. If this was not the case, it could be pointing to anything. This can lead to extremely unpleasant consequences to the computer. You should always initialize pointers before you use them.
It is also possible to initialize pointers using free memory. This allows dynamic allocation of array memory. It is most useful for setting up structures called linked lists. This difficult topic is too complex for this text. An understanding of the keywords new and delete will, however, be tremendously helpful in the future. The keyword new is used to initialize pointers with memory from free store (a section of memory available to all programs). The syntax looks like the example:
Code: [Select]
int *ptr = new int;
It initializes ptr to point to a memory address of size int (because variables have different sizes, number of bytes, this is necessary). The memory that is pointed to becomes unavailable to other programs. This means that the careful coder should free this memory at the end of its usage. The delete operator frees up the memory allocated through new. To do so, the syntax is as in the example.
Code: [Select]
delete ptr;
After deleting a pointer, it is a good idea to reset it to point to 0. When 0 is assigned to a pointer, the pointer becomes a null pointer, in other words, it points to nothing. By doing this, when you do something foolish with the pointer (it happens a lot, even with experienced programmers), you find out immediately instead of later, when you have done considerable damage.
Structures
Before discussing classes, this lesson will be an introduction to data structures similar to classes. Structures are a way of storing many different variables of different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. It is also useful for databases.
The format for declaring a structure (in C++, it is different in C) is
Code: [Select]
struct Tag {
Members
};
Where Tag is the name of the entire type of structure. To actually create a single structure the syntax is
Code: [Select]
Tag name_of_single_structure;
To access a variable of the structure it goes
Code: [Select]
name_of_single_structure.name_of_variable;
For example:
Code: [Select]
struct example {
int x;
};
example an_example; //Treating it like a normal variable type
an_example.x = 33; //How to access it's members
Here is an example program:
Code: [Select]
struct database {
int id_number;
int age;
float salary;
};
int main()
{
database employee; //There is now an employee variable that has modifiable
// variables inside it.
employee.age = 22;
employee.id_number = 1;
employee.salary = 12000.21;
}
The struct database declares that database has three variables in it, age, id_number, and salary. You can use database like a variable type like int. You can create an employee with the database type as I did above. Then, to modify it you call everything with the 'employee.' in front of it. You can also return structures from functions by defining their return type as a structure type. For instance:
Code: [Select]
database fn();
I will talk only a little bit about unions as well. Unions are like structures except that all the variables share the same memory. When a union is declared the compiler allocates enough memory for the largest data-type in the union. Its like a giant storage chest where you can store one large item, or a small item, but never the both at the same time.
The '.' operator is used to access different variables inside a union also.
As a final note, if you wish to have a pointer to a structure, to actually access the information stored inside the structure that is pointed to, you use the -> operator in place of the . operator. All points about pointers still apply.
A quick example:
Code: [Select]
#include <iostream>
using namespace std;
struct xampl {
int x;
};
int main()
{
xampl structure;
xampl *ptr;
structure.x = 12;
ptr = &structure; // Yes, you need the & when dealing with structures
// and using pointers to them
cout<< ptr->x; // The -> acts somewhat like the * when used with pointers
// It says, get whatever is at that memory address
// Not "get what that memory address is"
cin.get();
}
Sunday, 22 September 2013
0
Sunday, 22 September 2013
Unknown
Read More
Top 5 Computer Programmers in the World
Top 5 Computer Programmers in the World
In programming category we have written about History about programming language and Programming languages you're never heard of it, Now time to share about The best 10 Computer programmers around the world.
1. Dennis Ritchie
Dennis Ritchie (1941-2011) was an American Computer Programmer. Sir. Ritchie developed "C" programming language and co-developer of Unix Operating system. Dennis Ritchie worked for Alcatel-Lucent and for Bell labs.
Dennis Ritchie changed digital era by creating "C" programming language. Lisp, Visual Basic, Pascal, COBOL, Turbo pascal 7.0, PL/1, ADA, these are the programming languages are written in C programming language. "C" is a best programming language for newbie programmers, Who are interested in learning codes. Dennis Ritchie and his colleague Ken Thompson received the Turing award for implementing and developing UNIX operating system in the year 1983.
2. Mark Zuckerberg
Mark Zuckerberg created Facebook.com when he was 20 years old, Mark and his Harward university friends helped to build Facebook. When Facebook started it was only available for Hardward students. Facebook website is mainly written in C++ and PHP programming language. Mark is very passionate about programming and codes, In his early age he created a messenger called "Zucknet" that allowed to chat with all computers. In 2003 Mark createdFacemash, the website is all about comparing two Harward university students side by side "Hot or Not" contest. n last year Mark Zuckerberg earned more than $2 billion worth stock. And worth $15B according to report of usnews.
3. Steve Wozniak
The Brain behind Apple Inc. -Steve Wozniak is an Computer scientist and Programmer
Steve Woz is well known for developing Apple-1 and Apple-2 :
In early 1976 Woz and Jobs developed a Hardware ,Circuit Board design and Operating system for
Apple- 1 . Apple 1 priced around $666, And sold 50 system boards to Paul Terrell (Computer shop owner) . After Apple-1, Woz developed first Color graphics personal computer with Integer BASIC programming language and they named it as a
Apple-2. For sometime Steve Wozniak was teaching elementary school students about computer. In2006 Steve Woz published his autobiography iWoz: From Computer Geek to Cult Icon.Now Steve Woz is working for Fusion-io as a Chief Scientist.
4. Bill Gates
Bill Gates: Founder of world's largest software company Microsoft, And also Co-chairman of Gates Foundation. Also Bill gates is one of the world's richest man in the world. Bill started working with computer when he was 13 years old. When he was 17 Bill Gates formed a company called Traf-o-data. And In the age of 20 Bill Gates founded Microsoft Inc. Bill Gates also created MS-DOS Operating system and Windows OS. Currently Microsoft is one of the valuable company in the world. In 2012 Microsoft earns $73.72 Billion.
5. Linus Torvalds
Linus Torvalds is a software engineer, hacker and project coordinator. In 1991 Linus Torvalds released Linux 0.11 which is written in C programming language. Linux supports more than 20+ platforms. And Linux is a free and open source operating system, Open source means that you can get the source code of the operating system for free.
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program" - Linus Torvalds
The Top 5 Programmers lists ends here according to me but there are thousands of best programmers are there Larry page, Brin sergy, Bjarne Stroustrup.
Monday, 16 September 2013
0
Monday, 16 September 2013
Unknown
Read More
History of Programming Language
History of Programming Language
1940s:
1943 - Plankalkül (Konrad Zuse), designed, but unimplemented for a half-century
1943 - ENIAC, Electric Numerical Integrator And Computer, machine-specific codeset appearing in 1948.
1949 - 1954 — a series of machine-specific mnemonic instruction sets, like ENIAC's, beginning in 1949 with C-10 for BINAC (which later evolved into UNIVAC).Each codeset, or instruction set, was tailored to a specific manufacturer.
1950-1967s:
1951 - Regional Assembly Language
1952 - Autocode
1954 - IPL (forerunner to LISP)
1955 - FLOW-MATIC (forerunner to COBOL)
1957 - FORTRAN (First compiler)
1957 - COMTRAN (forerunner to COBOL)
1958 - LISP
1958 - ALGOL 58
1959 - FACT (forerunner to COBOL)
1959 - COBOL
1959 - RPG
1962 - APL
1962 - Simula
1962 - SNOBOL
1963 - CPL (forerunner to C)
1964 - BASIC
1964 - PL/I
1966 - JOSS
1967 - BCPL (forerunner to C)
1968-1979:
1968 - Logo
1969 - B (forerunner to C)
1970 - Pascal
1970 - Forth
1972 - C (Dennis Ritche)
1972 - Smalltalk
1972 - Prolog
1973 - ML
1975 - Scheme
1978 - SQL (initially only a query language, later extended with programming constructs)
1980s:
1980 - C++ (as C with classes, name changed in July 1983)
1983 - Ada
1984 - Common Lisp
1984 - MATLAB
1985 - Eiffel
1986 - Objective-C
1986 - Erlang
1987 - Perl
1988 - Tcl
1988 - Mathematica
1989 - FL (Backus);
1990s:
1990 - Haskell
1991 - Python
1991 - Visual Basic
1993 - Ruby
1993 - Lua
1994 - CLOS (part of ANSI Common Lisp)
1995 - Java (1991-1992 its name oak)
1995 - Delphi (Object Pascal)
1995 - JavaScript
1995 - PHP
1996 - WebDNA
1997 - Rebol
1999 - D
2000-current era:
2000 - ActionScript
2001 - C#
2001 - Visual Basic .NET
2002 - F#
2003 - Groovy
2003 - Scala
2003 - Factor
2007 - Clojure
2009 - Go
2011 - Dart.....
Subscribe to:
Posts (Atom)
