- #1
diredragon
- 323
- 15
Homework Statement
Analyze the code below and figure out what it outputs if it's started with this command:
The correct solution is given so i can better understand the parts of the problem.
Homework Equations
3. The Attempt at a Solution [/B]
I had typed it out and tried to get the same result on Visual Studio 2017 by passing it's command to Visual Debugger Command line Argument and it keeps outputting
Maybe i did something wrong with the command line? I do not know. I continued to analyze it by hand and i had a few questions along the way that were stopping me from figuring it out. Here is fully typed out and annotated code in which i showed my understanding of it.
C:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//./program.exe polisemija metonimija 0x1 2
void f(char *a, char *b, int c) {
if (a < b && c>0) f(a++, b--, c - 1);
*a = *a < *b ? *a : ++*b;
}
//argc = 5 and argv start from 0 with argv[0] = ./program.exe and end with argv[4] = 2
void main(int argc, char *argv[]) {
int c = atoi(argv[argc - 1]);
// c = 2;
char *p = argv[atoi(argv[3]) + 1],
//*p = argv[1 + 1] = "metonimija" but my debigger shows *p = "./program.exe"
//how can that be?
*q = p + strlen(p) - 1;
//here q = p + 13 - 1; if we take *p = "./program.exe" but what is p here ?
//my debugger gives q = 'e' so does this mean it points to 12th charachter of *p?
f(p, q, c);
printf("%s", p);