csc1254lect01

csc1254lect01 - CSc 1254: Lecture # 1 Review of Some C++...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSc 1254: Lecture # 1 Review of Some C++ August 22, 2005 Arrays Structures Typedef Vectors 1 Arrays Arrays are aggregate types in C++. They are more complex than scalars. Arrays are meant to store elements of the same type. You should already be familiar with how arrays are statically declared. Here is an example: #include <iostream> using namespace std; int main(int argc, char **argv) { int fourints[4]; return 0; } If an array is statically declared, then you cannot assign it to another array, even if the two arrays have the same type and the same number of elements. 1 #include <iostream> using namespace std; int main(int argc,char**argv) { int fourints1[4], fourints2[4]; fourints1[0] = fourints1[1] =fourints1[2] = fourints1[3] = 10; fourints2 = fourints1; /* illegal */ fourints2 = {10,10,10,10}; /* also, illegal */ return 0; } Lets say a word or two about argc and argv . A program may be run with command line tokens. argc stores the number of command line tokens and the argv array stores each of the tokens as strings. Thus argv[0] is the executable filename, argv[1] the next token, and so on. #include <iostream> #include<string> using namespace std; int main(int argc, char **argv) { int fourints[4]; fourints[0] = argc-1; fourints[1] = atoi(argv[1]); fourints[2] = atoi(argv[2]); fourints[3] = atoi(argv[3]); cout<<"The program"<<argv[0]<<"puts "<<fourints[0]<<" values -- " <<fourints[1]<<","<<fourints[2]<<","<<" and "<<fourints[3] <<" in the fourints array."<<endl; return 0; } If the program is compiled as argtest and we run the program from the command prompt as argtest 5 10 15 , we should see the output: The program argtest puts 3 values -- 5, 10, and 15 -- in the fourints array....
View Full Document

This note was uploaded on 01/16/2012 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 8

csc1254lect01 - CSc 1254: Lecture # 1 Review of Some C++...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online