Hi, I am trying to find 2nd largest number that given input of numbers. The question is actually consider that you enter 5 number : 60, 70, 30, 40, 55 randomly -the order does not matter- my function should find 2nd largest number and return it. I am trying but I did not manage to finish my code and actually I can not a way to find true algorithm for this question. The rule is -I know already how I can find max or min number in array, it is simple- [B]you do not use any type of array / …

Member Avatar
Member Avatar
+0 forum 8

#include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *first, *second, *third; first = malloc(888); second = malloc(22); third = malloc(22); strcpy(first, argv[1]); strcpy(second, argv[2]); free(first); free(second); free(third); return(0); } Like I said before, I need help learning C and trying to figure out my errors. With this code, am I vulnerable in terms of memory allocation? Could an attacker take advantage? If yes, please help me with your recommendations and guides Thanks

Member Avatar
Member Avatar
+0 forum 5

Hello, Please help me to overcome the following confussion. Suppose I have created an array of pointers like, A** l_aAPtr = new A*[l_iTotal]; for(int i = 0; i<l_iTotal;i++) { l_aAPtr[i] = new A(); } Now I want to delete this array. Please advise which of the following way is correct 1. for(int k = 0; k<l_iTotal;k++) { if(l_aAPtr[k]) { delete l_aAPtr[k]; l_aAPtr[k] = 0; } } if(l_aAPtr) { delete l_aAPtr; l_aAPtr = 0; } 2. for(int k = 0; k<l_iTotal;k++) { if(l_aAPtr[k]) { delete l_aAPtr[k]; l_aAPtr[k] = 0; } } if(l_aAPtr) { delete [] l_aAPtr; l_aAPtr = 0; } Thanks …

Member Avatar
Member Avatar
+0 forum 3

Hello I encountered following info at [this page](http://en.wikipedia.org/wiki/Call_stack#Overlap): For some purposes, the stack frame of a subroutine and that of its caller can be considered to overlap, the overlap consisting of the area where the parameters are passed from the caller to the callee. In some environments, the caller pushes each argument onto the stack, thus extending its stack frame, then invokes the callee. In other environments, the caller has a preallocated area at the top of its stack frame to hold the arguments it supplies to other subroutines it calls. This area is sometimes termed the outgoing arguments area …

Member Avatar
Member Avatar
+0 forum 1

The End.