#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
int main(void)
{
int dizi[10];
for(int i = 0; i < 10; i++)
dizi[i] = i * 2;
size_t size = sizeof(dizi)/sizeof(dizi[0]);
for(size_t i = 0; i < size; i++)
Console::WriteLine(dizi[i]);
// free(dizi); doesn't work...
// also i want to enlarge the array
return 0;
}
Sadun Sevingen - 18 Jul 2004 16:36 GMT
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#using <mscorlib.dll>
using namespace System;
int main() {
int number;
int *ptr;
int i;
printf("How many ints would you like store? ");
scanf("%d", &number);
ptr = (int *)(malloc(number*sizeof(int))); /* allocate memory */
if(ptr!=NULL) {
for(i=0 ; i<number ; i++) {
*(ptr+i) = i;
}
for(i=number ; i>0 ; i--) {
printf("%d\n", *(ptr+(i-1))); /* print out in reverse order */
}
free(ptr); /* free allocated memory */
return 0;
}
else {
printf("\nMemory allocation failed - not enough memory.\n");
return 1;
}
}
William DePalo [MVP VC++] - 19 Jul 2004 17:45 GMT
> #include "stdafx.h"
> #include "stdio.h"
[quoted text clipped - 6 lines]
> ....
> }
Is there a question here or is this homework? <g>
Regards,
Will
Sadun Sevingen - 21 Jul 2004 11:59 GMT
it was just a question that i was seeking for all kind of arrays that can i
use on VC++.net
i found
native arrays (value type, ref type)
system array called as managed array System:Array ther are ref type
and collections inherits from Array but much more efficient by indexing
functionalty "associativety"
but i don't have any idea about vectors i'ill look @ them...
William DePalo [MVP VC++] - 19 Jul 2004 17:44 GMT
> int main(void)
> {
> int dizi[10];
> ...
> // free(dizi); doesn't work...
It shouldn't as dizi is on the stack. The compiler effectively creates the
code to reclaim the memory for this object in the "epilog" code that it adds
to the function at its closing brace ( "}" )
Regards,
Will
Julie - 19 Jul 2004 18:09 GMT
> #include "stdafx.h"
> #using <mscorlib.dll>
[quoted text clipped - 16 lines]
> // also i want to enlarge the array
> ...
Yikes!
Look at std::vector instead, and get a good & current C++ programming book.