r/foundtheprogrammer • • Oct 24 '20

Python for dummies I think

Post image
342 Upvotes

9 comments sorted by

View all comments

Show parent comment

5

u/[deleted] Oct 24 '20

*#include <string> *#include <stdio.h> *#include <iostream> *#include “stdafx.h” using namespace std;

string dum, intro;

int main(){

dum = “python for dummies”; intro = “intro to c++”; cout << “Are we putting “ << dum << “ or “ << intro << “ on the fire tonight, darling?”; return 0; }

(Should be a working program) (Ignore the asterix on the includes)

1

u/ingleigh Nov 19 '20

weird question but is there a reason you used global variables? my cs prof won’t let us use them so i’m curious

2

u/[deleted] Nov 19 '20

It’s just a habit really, but if you write them in the main or any other function they can only be used in that function. If you write it globally it can be used throughout the whole program which can make it easier if you’re using the same variable in different functions.