summaryrefslogtreecommitdiff
path: root/4p9.cpp
blob: 101f1c9c7a8d5cc9394adc12f40b8119078c8330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

/*
 *
 * 4.9
 *
 *
 */

int main () {
	// True if:
	// the address pointed to isnt null
	// the first character isnt a null character

	// We can test this by making a string literal, for exmple "Hello world"
	// We can also test by putting the null character \0 in the string literal
	// And we can also test by pointing cp at nullptr
	int choice;
	const char *hw = "Hello world!";
	const char *np = nullptr;
	const char nc = '\0';
	const char *cp;
	std::cout << "1: Hello World | 2: nullptr | 3: null character" << std::endl;
	if(std::cin >> choice) {} else { return -1; }
	
	if(choice == 1) { cp = hw; }
	else if(choice == 2) { cp = np; }
	else if(choice == 3) { cp = &nc; }
	else { return -1; }
	
	if (cp && *cp) {
		std::cout << "valid" << std::endl;
	} else {
		std::cout << "not valid" << std::endl;
	}

	return 0;
}