IFT 339: Structures de données

Daniel Lemire, Ph.D.


Exercices 0 : Révision du C++ et l'enfer des pointeurs! (avec un peu de passage par référence)


for (int a = 1; a <= 1; a++) cout << a++; cout << a;

void foo(int j) {

int x = 5 ;

if( j == 0 ) {

int x ;

x = 3 ; }

return x ;

}

int n=1; if (n=0) cout << "n = 0"; else cout << "n = " << n;

for (int i=0; i<10; i++); cout << i%2 << " "; }

int number=1;

while (true) {

cout << number;

if (number == 3) break;

number += _value; }

int i = 2.5; do { cout i * 2; } while (i > 3 && i < 10);

#include <iostream>

#include <new>

using namespace std ;


int main() {

int *p = new(nothrow) int ;

if( p!=0 ) {

delete p ;

*p = 99 ;

cout << 12 << endl ; }

}

Matrix *strange( Matrix input ) {

Matrix *workMatrixP = new(nothrow) Matrix ;

*workMatrixP = input ;

for( int i = 0 ; i < workMatrixP->rows() ; ++i )

for( int j = 0 ; j < workMatrixP->cols() ; ++j )

if( i != j ) workMatrixP->set(i,j, 0.0) ;

return workMatrixP ; }

for( int i = 0 ; i < N ; ++i ) {

double *p = new(nothrow) double ;

if( p== 0 ) { return false ; }

*p = A[i] ; A[i] = B[i] ; B[i] = *p ; }

char *targetP ;

while( *sourceP ) {

*targetP = *sourceP ;

++targetP; ++sourceP ;

}

*targetP = '\0' ;

double *weird( double a, double b ) {

double c ;

c = pow( a*a + b*b, 0.5 ) ;

return &c ;

}

int &odd( int &r, int i ) {

r = i*i ;

return r ; }

ClassList *(x[N]) ;

ClassList ( *x )[N] ;

const char* w, x, y ;


1.*p = 10 ;

2.*q = 10

3.p = x;

4.q = y ;