SlideShare a Scribd company logo
Exercises: 
1) General questions: 
a) How can we pass an array by value? 
b) How can we pass an int by reference? 
c) How can we retrieve the length of an array? 
d) How can we append new items to an array? 
2) Get acquainted with the usage of arrays. What happens if you create an array of size 
ten and: 
a) access the element at index 10? 
b) access the element at index -1? 
Document the results with screenshots if required. 
3) Create a function that accepts at least two array arguments. The function should copy 
the content of one array into the other array. 
a) Write a test program to test your function. 
b) Which error cases do you need to handle in this function? 
4) What happens if you dereference a 0-pointer? Document the result with screenshots if 
required. 
5) Re-implement the program that calculates to sum of squares with an array of five 
items. 
6) Learn how to get and process command line arguments of a C++ program. Also learn 
how you can pass these arguments from within your IDE in order to debug the 
program. You need this information in the next exercise. 
7) In another program the user should input a string via command line arguments. The 
program checks, whether the passed string is a palindrome. A palindrome is a 
"symmetric" word, i.e. such a word that can be read from left to right and from right to 
left having the same wording, e.g. "otto", "anna", "lagerregal". After the check following 
output should be generated: "anna is a palindrome". The case of the word's letters 
should be regarded, so "Otto" is no palindrome. The check for a word to be a 
palindrome should be implemented in a single function with following signature: 
bool IsPalindrome(const char* word); 
A function, which tests an argument against a criterion is sometimes called predicate. 
8) Develop a function that awaits a source string and a substring. The result of this 
function is the count of occurrences of the substring in the source string. This function 
will have following signature: 
int CountSubString(const char* source, const char* subString); 
The functionality of the function should be proved with a test program. 
9) Write a void-function that returns an int-value via a parameter. 
Remarks: 
• Everything that was left unspecified can be solved as you prefer. 
• The usage of goto, C++11 extensions, as well as #pragmas is not allowed. The usage 
of global variables is not allowed. You mustn't use the STL (e.g. std::string), but 
std::cout, std::cin and belonging to manipulators can be used. You mustn't use new 
and delete! You are not allowed to use C++ references instead of pointers. 
• Avoid magic numbers and use constants where possible. 
• The results of the programming exercises need to be runnable applications! All
programs have to be implemented as console programs. 
• The programs need to be robust, i.e. they should cope with erroneous input from the 
user. 
• You should be able to describe your programs after implementation. Comments are 
mandatory. 
• In documentations as well as in comments, strings or user interfaces make correct use 
of language (spelling and grammar)! 
• Don't send binary files (e.g. the contents of debug/release folders) with your solutions! 
Do only send source and project files. 
• Don't panic: In programming multiple solutions are possible. 
• If you have problems use the Visual Studio help (F1) or the Xcode help, books and the 
internet primarily. 
• Of course you can also ask colleagues; but it is of course always better, if you find a 
solution yourself.

More Related Content

DOCX
C quiz
PDF
100% code coverage by static analysis - is it that good?
PDF
Functions
ODP
PDF
Go go power slice
PPT
C++ Introduction
ODP
Template classes and ROS messages
PPTX
Infix-Postfix expression conversion
C quiz
100% code coverage by static analysis - is it that good?
Functions
Go go power slice
C++ Introduction
Template classes and ROS messages
Infix-Postfix expression conversion

What's hot (17)

PPT
Unit iv
PDF
computer notes - Evaluating postfix expressions
DOCX
Revision test of unit
PDF
The c++coreguidelinesforsavercode
PDF
computer notes - Conversion from infix to postfix
PDF
VivaMP, system of detecting errors in the code of parallel C++ programs using...
PDF
A tutorial on C++ Programming
PDF
Unit testing.pptx [repaired]
PDF
PDF
Pointers c5
PPTX
Infix to postfix conversion
PDF
OOPS With CSharp - Jinal Desai .NET
PPT
Polyspace CETIC presentation
PDF
First program of C ( Complete Explanation )
PDF
[C++ korea] effective modern c++ study item 4 - 6 신촌
PPT
Exceptions
PPTX
Exception handling chapter15
Unit iv
computer notes - Evaluating postfix expressions
Revision test of unit
The c++coreguidelinesforsavercode
computer notes - Conversion from infix to postfix
VivaMP, system of detecting errors in the code of parallel C++ programs using...
A tutorial on C++ Programming
Unit testing.pptx [repaired]
Pointers c5
Infix to postfix conversion
OOPS With CSharp - Jinal Desai .NET
Polyspace CETIC presentation
First program of C ( Complete Explanation )
[C++ korea] effective modern c++ study item 4 - 6 신촌
Exceptions
Exception handling chapter15
Ad

Similar to (4) cpp automatic arrays_pointers_c-strings_exercises (20)

ODT
(6) cpp numeric representation_exercises
ODT
(3) cpp abstractions more_on_user_defined_types_exercises
ODT
(3) cpp procedural programming_exercises
PDF
Tutorial basic of c ++lesson 1 eng ver
DOCX
C language tutorial
DOCX
C++ question and answers
PPT
1.3 Basic coding skills_tupels_sets_controlloops.ppt
PPT
1.3 Basic coding skills_fundamentals .ppt
PPT
Basic coding skills_python and its applications
PDF
Boo Manifesto
PDF
I x scripting
PPTX
Introduction Of C++
PDF
علم البيانات - Data Sience
DOCX
Goals1)Be able to work with individual bits in java.2).docx
PPTX
C++ lecture 01
PDF
88 c programs 15184
PDF
88 c-programs
PDF
Project lexical analyser compiler _1.pdf
(6) cpp numeric representation_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp procedural programming_exercises
Tutorial basic of c ++lesson 1 eng ver
C language tutorial
C++ question and answers
1.3 Basic coding skills_tupels_sets_controlloops.ppt
1.3 Basic coding skills_fundamentals .ppt
Basic coding skills_python and its applications
Boo Manifesto
I x scripting
Introduction Of C++
علم البيانات - Data Sience
Goals1)Be able to work with individual bits in java.2).docx
C++ lecture 01
88 c programs 15184
88 c-programs
Project lexical analyser compiler _1.pdf
Ad

More from Nico Ludwig (20)

PPTX
Grundkurs fuer excel_part_v
PPTX
Grundkurs fuer excel_part_iv
PPTX
Grundkurs fuer excel_part_iii
PPTX
Grundkurs fuer excel_part_ii
PPTX
Grundkurs fuer excel_part_i
PDF
(2) gui drawing
ODP
(2) gui drawing
PDF
(1) gui history_of_interactivity
ODP
(1) gui history_of_interactivity
PDF
New c sharp4_features_part_vi
PDF
New c sharp4_features_part_v
PDF
New c sharp4_features_part_iv
ODP
New c sharp4_features_part_iii
PDF
New c sharp4_features_part_ii
PDF
New c sharp4_features_part_i
PDF
New c sharp3_features_(linq)_part_v
PDF
New c sharp3_features_(linq)_part_iv
ODP
New c sharp3_features_(linq)_part_iv
PDF
New c sharp3_features_(linq)_part_iii
PDF
New c sharp3_features_(linq)_part_ii
Grundkurs fuer excel_part_v
Grundkurs fuer excel_part_iv
Grundkurs fuer excel_part_iii
Grundkurs fuer excel_part_ii
Grundkurs fuer excel_part_i
(2) gui drawing
(2) gui drawing
(1) gui history_of_interactivity
(1) gui history_of_interactivity
New c sharp4_features_part_vi
New c sharp4_features_part_v
New c sharp4_features_part_iv
New c sharp4_features_part_iii
New c sharp4_features_part_ii
New c sharp4_features_part_i
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_ii

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25-Week II
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Encapsulation_ Review paper, used for researhc scholars

(4) cpp automatic arrays_pointers_c-strings_exercises

  • 1. Exercises: 1) General questions: a) How can we pass an array by value? b) How can we pass an int by reference? c) How can we retrieve the length of an array? d) How can we append new items to an array? 2) Get acquainted with the usage of arrays. What happens if you create an array of size ten and: a) access the element at index 10? b) access the element at index -1? Document the results with screenshots if required. 3) Create a function that accepts at least two array arguments. The function should copy the content of one array into the other array. a) Write a test program to test your function. b) Which error cases do you need to handle in this function? 4) What happens if you dereference a 0-pointer? Document the result with screenshots if required. 5) Re-implement the program that calculates to sum of squares with an array of five items. 6) Learn how to get and process command line arguments of a C++ program. Also learn how you can pass these arguments from within your IDE in order to debug the program. You need this information in the next exercise. 7) In another program the user should input a string via command line arguments. The program checks, whether the passed string is a palindrome. A palindrome is a "symmetric" word, i.e. such a word that can be read from left to right and from right to left having the same wording, e.g. "otto", "anna", "lagerregal". After the check following output should be generated: "anna is a palindrome". The case of the word's letters should be regarded, so "Otto" is no palindrome. The check for a word to be a palindrome should be implemented in a single function with following signature: bool IsPalindrome(const char* word); A function, which tests an argument against a criterion is sometimes called predicate. 8) Develop a function that awaits a source string and a substring. The result of this function is the count of occurrences of the substring in the source string. This function will have following signature: int CountSubString(const char* source, const char* subString); The functionality of the function should be proved with a test program. 9) Write a void-function that returns an int-value via a parameter. Remarks: • Everything that was left unspecified can be solved as you prefer. • The usage of goto, C++11 extensions, as well as #pragmas is not allowed. The usage of global variables is not allowed. You mustn't use the STL (e.g. std::string), but std::cout, std::cin and belonging to manipulators can be used. You mustn't use new and delete! You are not allowed to use C++ references instead of pointers. • Avoid magic numbers and use constants where possible. • The results of the programming exercises need to be runnable applications! All
  • 2. programs have to be implemented as console programs. • The programs need to be robust, i.e. they should cope with erroneous input from the user. • You should be able to describe your programs after implementation. Comments are mandatory. • In documentations as well as in comments, strings or user interfaces make correct use of language (spelling and grammar)! • Don't send binary files (e.g. the contents of debug/release folders) with your solutions! Do only send source and project files. • Don't panic: In programming multiple solutions are possible. • If you have problems use the Visual Studio help (F1) or the Xcode help, books and the internet primarily. • Of course you can also ask colleagues; but it is of course always better, if you find a solution yourself.