Command Line Arguments
Command Line Arguments
🔹 Parameters:
#include <stdio.h>
#include <stdlib.h> // for atoi()
return 0;
}
🟩 Output:
Sum of 12 and 8 is 20
✅ Explanation:
Code Meaning
argc != 3 Checks if 2 numbers (and program name) are provided
argv[0] Program name (e.g., ./add)
argv[1], argv[2] Command line inputs (e.g., "12", "8")
atoi(argv[1]), atoi(argv[2]) Convert string to integer
#include <stdio.h>
#include <stdlib.h>
int a = atoi(argv[1]);
int b = atoi(argv[2]);
Run:
./program 10 20
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s <num1> <num2>\n", argv[0]);
return 1;
}
int a = atoi(argv[1]);
int b = atoi(argv[2]);
Run:
./program 5 6
#include <stdio.h>
#include <string.h>
Run:
./program hello
✅ 4. Reverse a String
#include <stdio.h>
#include <string.h>
return 0;
}
Run:
./program world
#include <stdio.h>
What is ASCII in C
ASCII stands for American Standard Code for Information Interchange.
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
Output:
Enter a character: A
ASCII value of 'A' = 65
int main() {
char ch;
printf("Enter a lowercase letter: ");
scanf("%c", &ch);
Output:
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
Output:
Enter a character: 5
'5' is a digit.
#include <stdio.h>
int main() {
for (int i = 0; i < 128; i++) {
printf("ASCII %3d = %c\n", i, i);
}
return 0;
}
🟢 Output:
ASCII 0 =
ASCII 1 =
...
ASCII 65 = A
ASCII 97 = a
...
ASCII 127 = ⌂
#include <stdio.h>
int main() {
char str[] = "Hello ASCII World!";
int count = 0;
🟢 Output: