Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to C++
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Related Services

Bookmark and Share
Lecture Comments (12)

0 answers

Post by ALI SAAD on January 6 at 12:55:51 PM

Is there any plan to do  Data structure lectures?

1 answer

Last reply by: Alvin Sylvain
Sun Sep 28, 2014 3:41 PM

Post by Ram Manohar Oruganti on September 23, 2014

What's the advantage of using new and delete over normal array allocation?

1 answer

Last reply by: Alvin Sylvain
Fri Feb 7, 2014 6:29 PM

Post by Ram Manohar Oruganti on February 7, 2014

char name[10] = {'a','b','c','d','e','f','g','h','i','\0'};
cout<<name<<endl; //prints abcdefghi
char name[10] = {'a','b','c','d','e','f','g','h','i','j'};
cout<<name<<endl; //prints abcdefghij and some garbage values
So is the null terminator an indicator to the arry to stop raing from the next memory location? Would it continue reading until it encounters a null terminator? Thanks in advance.

3 answers

Last reply by: Alvin Sylvain
Sun Jun 30, 2013 10:27 AM

Post by Brandon Oakley on June 27, 2013

Hey Allan, I was doing pretty good in this course with the homeworks up until this problem set (arrays and pointers).. I hit a road block as I can't even program the first one for some reason.. I don't know if its because I am trying to initialize arrays wrong or.... Anywho, could you possibly offer a solution/ plan of attack template that will aid me in solving this homework? I am trying to move on with the course but I feel as though if I cannot get a grasp on this then whats the point of trying what is ahead

2 answers

Last reply by: Katenderi Mohamed
Wed Jul 18, 2012 4:41 AM

Post by Katenderi Mohamed on July 17, 2012

I have this game but I am not sure how to start writing its code, please can you help me out?

This function is required for the 'GAME' programming project in *

* This ffunction: *
1. Checks the board[][] array for a winner and returns
PLYR_TOKEN if player has won
COMP_TOKEN if computer has won
NONE if there is no winner yet
2. Analyses the current status of the game and determines priority values for each unoccupied place on the board and 'stores these in an array called place_val'.
3. Requires place_val to be passed to it.

Arrays & Pointers

  • Arrays are used for multiple pieces of data saved in a “chunk” of memory that the compiler will allocate
  • The size of the array is declared using square brackets
  • Square brackets are also used to specify which element of the array to work with in an expression
  • Arrays may be multi-dimensional
  • Arrays may be initialized at compile-time, which saves run-time and programmer effort for reference arrays
  • Character strings are a special case for initialing character arrays
  • Pointers are used to store the location, or the address, where data is stored, not the data itself
  • Use reference and dereference operators when working with pointers
  • Use pointer arithmetic when the pointer points into an array
  • Arrays passed as function parameters are “call by reference”, never “call by value”, since copying a large array can be impractical
  • Operators “new” and “delete” are used to allocate and de-allocate memory for arrays at run-time
  • Here are links to more information about C++ arrays and pointers:

Arrays & Pointers

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Overview 0:10
  • Use a 'Chunk' of Memory 3:22
  • Declaring an Array 6:27
    • Example
  • Select an Element From Array 8:44
    • Example
  • Multi-Dimensional Array 12:15
    • Examples
  • Compile-Time Initialization 14:18
    • Example
  • Multi-Initialization 16:27
  • Character String Initialization 18:27
    • Examples
  • Pointers 20:11
    • Example
    • Pointer Declaration
    • Reference Operator
  • Referencing and Dereferencing 24:30
    • Example
  • Pointer Arithmetic 27:10
  • Function Call-By Reference 31:06
  • Function Array/ Pointer Example 32:21
  • Null Terminated Character Arrays 34:22
    • Example
  • 'New' and 'Delete' 36:31
    • Example
  • Array of Pointers 40:19