Basic C++ Intro (Arrays, clang & arguments at the command line)

//how to declare an array of type int with 3 different scores
int scores[3];
#include <stdio.h>
#include <cs50.h>
#include <math.h>
#include <string.h>

// functions declarations
int string_length(string s); //prototype of function

int main(void)
    string name = get_string("name: ");
    char letter;
    int i = 0;

    while (name[i] != '\0')
        letter = name[i];
        printf("%i %c\n", i, letter);
    printf("%i\n", i);

    //use of function
    name = get_string("Enter your name again: ");
    i = string_length(name);
    printf("new string %i\n", i);

    //use of cs50 function
    name = get_string("yet another string: ");
    i = strlen(name);
    printf("third string is %i characters long\n", i);
}//int main(void)

//The above code can be turned into a function, the function will return an integer
int string_length(string s)
    int i = 0;
    while (s[i] != '\0')
    return i;
}//int string_length(string s)

$clang hello.c will create a.out which stands for assembly.out

clang <file name input>This will compile a c++ file the
output will be a file called a.out
clang -o <file name output> <file name input>-o means output and the desired
name for the compiled file.
clang -o <file name output> <file name input> -l<library>-l links the libraries required to
compile the program
#include <stdio.h>

int main(int argc, string argv[])

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *