Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Basic C, C++
Description: What a need say to me

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


C/C++ Basics

Basic Concepts
• Basic functions of each language: Input,
output, math, decision, repetition
• Types of errors: Syntax errors, logic errors,
runtime errors
...


SW Complexity

SW
Complexity

ideal

Size of the application – Lines of Code

Object-Oriented Programming
Programming
Interface

Object
Attributes (data)
typically private to this object

Other
objects

Methods
(behaviors / procedures)
1-8

C vs
...

• …

C++ vs
...
Most OOP library contents
are similar, however Java continues to grow
...
Easy to learn the other language
when you know one of these
...
Java: differences
C++
Write once, compile everywhere
executable for each target

Java
unique

Write once, run anywhere same class
files will run above all target-specific JREs
...
Typically, a header file and
implementation file are used for each class
...
g
...
java

I/O statements use cin and cout, e
...

cin >> x;
cout << y;

I/O input mechanism is bit more complex,
since default mechanism reads one byte at
a time (System
...
Output is easy, e
...

System
...
println(x);

Pointers, References, and pass by value are
supported
...


Primitive data types always passed by value
...
Array
bounds are always checked
...
Supports
destructors
...


Supports operator overloading
...


C standard library
• http://en
...
org/wiki/C_standard_library
• stdio
...
h: atof(), atoi(), rand(), srand(), malloc(), free(), …
• math
...
h: strcpy(), strcmp(), …
• ctype: isdigit(), isalpha(), tolower(), toupper()
• …

Sample C programs: prog1
...
h>
main()
{
int in1, out;
double in2;
puts("Enter values:");
scanf("%d%lf", &in1, &in2); // & means "address of"
// %d int, %f float, %lf double
out = in1 + in2;
printf("Output is %d\n", out);
}

Sample C programs: prog2
...
h>
#include ...
c
#include ...
h>
main()
{
srand(getpid());
printf("%d\n", rand());
printf("%d\n", rand());
printf("%d\n", rand());
}

Sample C programs: prog4
...
h>
int add(int x, int y)
{
return x + y;
}
main()
{
int in1, in2, out;
puts("Enter values:");
scanf("%d%d", &in1, &in2);
out = add(in1, in2);
printf("Output is %d\n", out);
}

Sample C programs: simple
...
h>
main()
{
int i, arr[10];
puts("Let me init the array contents
...
c
#include ...
");
for( i=0 ; i<20 ; i++)
arr[i] = i;
puts("Well, I survived!");
return 0;
}

Sample C programs: simple1
...
h>
int i, array[10], array2[10];
main()
{
puts("\nArray's contents are");
for( i=0 ; i<10 ; i++)
printf("%d\n",array[i]);
puts("\nArray2's contents are");
for( i=0 ; i<10 ; i++)
printf("%d\n",array2[i]);
puts("Let me init the array contents
...
c
#include ...
");
for( i=-10 ; i<20 ; i++)
array[i] = i;
puts("\nArray's contents are");
printArray(array);
puts("\nArray2's contents are");
printArray(array2);
puts("\nWell, I survived!");
return 0;

Sample C programs: simple3
...
h>

main()
{
int i, array[10], array2[10];

printArray(int *arr)
{
int i;
for(i=0 ; i<10 ; i++)
printf("%d\n",arr[i]);

puts("\nArray's contents are");
printArray(array);
puts("\nArray2's contents are");
printArray(array2);

}

puts("Let me init array contents
...
c
#include ...
");
main()
for( i=-10 ; i<20 ; i++)
{
array[i] = i;
second();
puts("\nArray's contents are");
puts("\nWell, I survived!");
printArray(array);
return 0;
puts("\nArray2's contents are");
}
printArray(array2);
}

Things to observe





Memory allocation for arrays
Array length is not stored with arrays
Potentional issues with scanf() and printf()
Different behavior when overshooting arrays
in heap vs
...
java

file2
...
java



filen
...
c

file2
...
c



filen
...

Most used commands:
• run
• list [method name]
• break [line_number]
• step
• next
• continue
• print [variable]


Title: Basic C, C++
Description: What a need say to me