mirror of
				https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
				synced 2025-11-03 16:52:33 +00:00 
			
		
		
		
	investigated the options to return an array from a function
This commit is contained in:
		
							parent
							
								
									d3138a4b13
								
							
						
					
					
						commit
						d6287d6002
					
				
							
								
								
									
										29
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
			
		||||
{
 | 
			
		||||
    // Use IntelliSense to learn about possible attributes.
 | 
			
		||||
    // Hover to view descriptions of existing attributes.
 | 
			
		||||
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 | 
			
		||||
    "version": "0.2.0",
 | 
			
		||||
    "configurations": [
 | 
			
		||||
        {
 | 
			
		||||
            "name": "g++.exe - Build and debug active file",
 | 
			
		||||
            "type": "cppdbg",
 | 
			
		||||
            "request": "launch",
 | 
			
		||||
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
 | 
			
		||||
            "args": [],
 | 
			
		||||
            "stopAtEntry": false,
 | 
			
		||||
            "cwd": "${fileDirname}",
 | 
			
		||||
            "environment": [],
 | 
			
		||||
            "externalConsole": false,
 | 
			
		||||
            "MIMode": "gdb",
 | 
			
		||||
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
 | 
			
		||||
            "setupCommands": [
 | 
			
		||||
                {
 | 
			
		||||
                    "description": "Enable pretty-printing for gdb",
 | 
			
		||||
                    "text": "-enable-pretty-printing",
 | 
			
		||||
                    "ignoreFailures": true
 | 
			
		||||
                }
 | 
			
		||||
            ],
 | 
			
		||||
            "preLaunchTask": "C/C++: g++.exe build active file"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
    "files.associations": {
 | 
			
		||||
        "iterator": "cpp"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
			
		||||
{
 | 
			
		||||
    "tasks": [
 | 
			
		||||
        {
 | 
			
		||||
            "type": "cppbuild",
 | 
			
		||||
            "label": "C/C++: g++.exe build active file",
 | 
			
		||||
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
 | 
			
		||||
            "args": [
 | 
			
		||||
                "-fdiagnostics-color=always",
 | 
			
		||||
                "-g",
 | 
			
		||||
                "${file}",
 | 
			
		||||
                "-o",
 | 
			
		||||
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
 | 
			
		||||
            ],
 | 
			
		||||
            "options": {
 | 
			
		||||
                "cwd": "${fileDirname}"
 | 
			
		||||
            },
 | 
			
		||||
            "problemMatcher": [
 | 
			
		||||
                "$gcc"
 | 
			
		||||
            ],
 | 
			
		||||
            "group": {
 | 
			
		||||
                "kind": "build",
 | 
			
		||||
                "isDefault": true
 | 
			
		||||
            },
 | 
			
		||||
            "detail": "Task generated by Debugger."
 | 
			
		||||
        }
 | 
			
		||||
    ],
 | 
			
		||||
    "version": "2.0.0"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										30
									
								
								Freestyle/ret_multiple_types.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								Freestyle/ret_multiple_types.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <iterator>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
void ret_array(int *ret,  int amount){
 | 
			
		||||
    for(int i=0;i<amount;i++)
 | 
			
		||||
        //*(ret+i)=+1;
 | 
			
		||||
        ret[i]=i*2; // Simpler because arrays are already pointers: startloc + typesize*<index>
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
int* ret_array2(){
 | 
			
		||||
    static const int amount = 10;
 | 
			
		||||
    static int ret[amount];
 | 
			
		||||
    for(int i=0;i<amount;i++)
 | 
			
		||||
        *(ret+1*i)=i*3;
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
int main(){
 | 
			
		||||
 | 
			
		||||
    int new_array[10];
 | 
			
		||||
    ret_array(new_array,10); //Array is already a pointer, pointing to the first element;
 | 
			
		||||
    for(int i:new_array)
 | 
			
		||||
        cout <<"Number "<<i<<endl;
 | 
			
		||||
 | 
			
		||||
    int *arr2= ret_array2();
 | 
			
		||||
    for(int i=0;i<10;i++)
 | 
			
		||||
        cout <<"Number "<<arr2[i]<<endl;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Freestyle/ret_multiple_types.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Freestyle/ret_multiple_types.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
    for(int i=1; i<=100;i++){
 | 
			
		||||
        if(i%2!=0) continue;
 | 
			
		||||
        cout<<i<<endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Teil_1/4. Kontrollstrukturen/Uebung 6 - Continue-Anweisung.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Teil_1/4. Kontrollstrukturen/Uebung 6 - Continue-Anweisung.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										24
									
								
								Teil_1/5. Felder/Uebung 1 - Bauernhof.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Teil_1/5. Felder/Uebung 1 - Bauernhof.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,24 @@
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
struct Tier{
 | 
			
		||||
    uint8_t id;
 | 
			
		||||
    string name;
 | 
			
		||||
    bool operator == (const Tier& cmp) const {return id==cmp.id;}
 | 
			
		||||
    bool operator < (const Tier& cmp) const {return id-cmp.id;}
 | 
			
		||||
    string to_string(){return "ID: "+id+(name.length()>0?("Name: "+name):"")+"\n";}
 | 
			
		||||
};
 | 
			
		||||
int main(){
 | 
			
		||||
    Tier tiere[50];
 | 
			
		||||
    cout<<"Erstelle Liste\n";
 | 
			
		||||
    for(int i = 0;i<50;i++){
 | 
			
		||||
        cout<<"Erstelle index "<<i<<endl;
 | 
			
		||||
        tiere[i].id=i+1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for(Tier tier:tiere){
 | 
			
		||||
        cout<<tier.to_string()<<endl;
 | 
			
		||||
    }
 | 
			
		||||
    system("pause");
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								Teil_1/5. Felder/Uebung 1 - Bauernhof.exe
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Teil_1/5. Felder/Uebung 1 - Bauernhof.exe
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user