Skip to main content

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But iI get crazy resulstincorrect results (huge- huge numbers) even for small inputs like 5 and 10. I have no idea whatWhat is wrong there, can someone help pleasehere?

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But i get crazy resulst (huge numbers) even for small inputs like 5 and 10. I have no idea what is wrong there, can someone help please?

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But I get incorrect results - huge numbers even for small inputs like 5 and 10. What is wrong here?

added 1 characters in body
Source Link
PeterK
  • 6.3k
  • 6
  • 55
  • 87

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <cstdlib><stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But i get crazy resulst (huge numbers) even for small inputs like 5 and 10. I have no idea what is wrong there, can someone help please?

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <cstdlib> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But i get crazy resulst (huge numbers) even for small inputs like 5 and 10. I have no idea what is wrong there, can someone help please?

please forgive me if this is a noob question, but i'm a beginner at C, learning only for a while. I tried to write a program that sums up two numbers (provided as params to the application). The code is like this:

#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv) { int a = atoi(argv[0]); int b = atoi(argv[1]); int sum = a+b; printf("%d", sum); return 0; } 

But i get crazy resulst (huge numbers) even for small inputs like 5 and 10. I have no idea what is wrong there, can someone help please?

fixed typo in title
Link
Adam Crossland
  • 14.2k
  • 3
  • 47
  • 56

Acessing Accessing command line arguments in C

Source Link
PeterK
  • 6.3k
  • 6
  • 55
  • 87
Loading