Skip to content
Snippets Groups Projects
Commit bd7413ee authored by Jake Feddersen's avatar Jake Feddersen
Browse files

Updating stuff and notes and everything

parent ac7aba0a
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
No preview for this file type
#include <stdio.h>
//char *s = "String 4";
char *s = "String 4";
char *strings[] = {
"String 1",
......
File added
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
const int i = 7;
cout << i << endl;
*(int *) &i = 5;
cout << i << endl;
return 0;
}
File added
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "Hello World!" << endl;
return 0;
}
File added
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
volatile const int i = 7;
cout << i << endl;
*(int *) &i = 5;
cout << i << endl;
return 0;
}
#ifndef STRING327_H
#define STRING327_H
class string327 {
private:
char *str;
public:
string327();
string327(const char *s);
~string327();
int length();
const char *c_str();
int operator<(const string327 &s);
int operator>(const string327 &s);
int operator==(const string327 &s);
int operator!=(const string327 &s);
int operator<=(const string327 &s);
int operator>=(const string327 &s);
string327 operator+(const string327 &s);
string327 &operator+=(const string327 &s);
string327 &operator=(const string327 &s);
string327 &operator=(const char *s);
char &operator[](const int i);
};
#endif
File added
#include <iostream>
using namespace std;
void cswap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
void cppswap(int &a, int &b) {
int tmp = a;
a = b;
b = tmp;
}
int main(int argc, char *argv[]) {
int i;
int &r = i;
r = 0;
cout << i << endl;
i = 10;
cout << r << endl;
int a = 10, b = 20;
cswap(&a, &b);
printf("a: %d, b: %d\n", a, b);
cppswap(a, b);
printf("a: %d, b: %d\n", a, b);
return 0;
}
#include <cstring>
#include "string327.h"
string327::string327() {
str = (char *) malloc(1);
str[0] = '\0';
}
string327::string327(const char *s) {
str = strdup(s);
}
string327::~string327() {
free(str);
}
int string327::length() {
return strlen(str);
}
const char *string327::c_str() {
return str;
}
int string327::operator<(const string327 &s) {
return strcmp(str, s.str) < 0;
}
int string327::operator>(const string327 &s) {
return strcmp(str, s.str) > 0;
}
int string327::operator==(const string327 &s) {
return strcmp(str, s.str) == 0;
}
int string327::operator!=(const string327 &s) {
return strcmp(str, s.str) != 0;
}
int string327::operator<=(const string327 &s) {
return strcmp(str, s.str) <= 0;
}
int string327::operator>=(const string327 &s) {
return strcmp(str, s.str) >= 0;
}
string327 string327::operator+(const string327 &s) {
string327 out;
free(out.str);
out.str = malloc(strlen(str) + strlen(s.str) + 1);
strcpy(out.str, str);
strcat(out.str, s.str);
return out;
}
string327 &string327::operator+=(const string327 &s) {
str = (char *) realloc(str, strlen(str) + strlen(s.str) + 1);
strcat(str, s.str);
return *this;
}
string327 &string327::operator=(const string327 &s) {
free(str);
str = strdup(s.str);
return *this;
}
string327 &string327::operator=(const char *s) {
free(str);
str = strcup(s);
}
char &string327::operator[](const int i) {
return str[i];
}
#ifndef STRING327_H
#define STRING327_H
class string327 {
private:
char *str;
public:
string327();
string327(const char *s);
~string327();
int length();
const char *c_str();
int operator<(const string327 &s);
int operator>(const string327 &s);
int operator==(const string327 &s);
int operator!=(const string327 &s);
int operator<=(const string327 &s);
int operator>=(const string327 &s);
string327 operator+(const string327 &s);
string327 &operator+=(const string327 &s);
string327 &operator=(const string327 &s);
string327 &operator=(const char *s);
char &operator[](const int i);
};
#endif
#include <iostream>
#include "string327.h"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment