This set of slides introduces the reader to the concept of multidimensional arrays in C++ (with elements of C++11 and C++14). The true nature of multidimensional arrays is discussed by means of an intermediate type alias. The pheonomenon of array-to-pointer decay and pointer arithmetic is then generalized to arrays of arrays. The presentation proceeds with a discussion on how to pass multidimensional arrays to functions.
Arrays are complex variables that can hold multiple values of the same data type.
Array is a fixed type sequenced collection of elements of the same data type.
It is simply a grouping of like-type data.
Some examples where a concept of arrays can be used :-
1) List of employees in an organization.
2) Exam scores of a class of students.
3) Table of daily rainfall data.
Arrays are complex variables that can hold multiple values of the same data type.
Array is a fixed type sequenced collection of elements of the same data type.
It is simply a grouping of like-type data.
Some examples where a concept of arrays can be used :-
1) List of employees in an organization.
2) Exam scores of a class of students.
3) Table of daily rainfall data.
Array
Introduction
One-dimensional array
Multidimensional array
Advantage of Array
Write a C program using arrays that produces the multiplication of two matrices.
2D array in C++ language ,define the concept of c++ Two-Dimensional array .with example .and also Accessing Array Components concept.and Processing Two-Dimensional Arrays.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
Array
Introduction
One-dimensional array
Multidimensional array
Advantage of Array
Write a C program using arrays that produces the multiplication of two matrices.
2D array in C++ language ,define the concept of c++ Two-Dimensional array .with example .and also Accessing Array Components concept.and Processing Two-Dimensional Arrays.
C Programming/Strings. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '-' . So, a string with the contents, say, "abc" has four characters: 'a' , 'b' , 'c' , and the terminating null character.
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.
There are few important operations, which we will do with the help of pointers very frequently. (a) we define a pointer variable (b) assign the address of a variable to a pointer and (c) finally access the value at the address available in the pointer variable. This is done by using unary operator * that returns the value of the variable located at the address specified by its operand.
This set of slides introduces the reader to the concept of arrays in C++ (with elements of C++11 and C++14). After presenting the array data type, the concept of array-to-pointer decay is introduced. The presentation proceeds with a discussion on how to pass arrays to functions. To this extent, the reader is guided to the use of bounded ranges as the first step towards the use of the Standard Template Library (STL).
Visual programming (VP) refers to a method of programming that uses a graphical interface to create and modify code, rather than typing out code manually. Unlike traditional text-based programming, visual programming uses visual elements to represent code. Some graphical elements you can use when creating programs with VP include:
An array consists of a set of objects (called its elements), all of which are of the same type and are arranged contiguously in memory. In general, only the array itself has a symbolic name, not its elements. Each element is identified by an index which denotes the position of the element in the array. The number of elements in an array is called its dimension. The dimension of an array is fixed and predetermined; it cannot be changed during program execution.
Arrays are suitable for representing composite data which consist of many similar, individual items. Examples include: a list of names, a table of world cities and their current temperatures, or the monthly transactions for a bank account.
A pointer is simply the address of an object in memory. Generally, objects can be accessed in two ways: directly by their symbolic name, or indirectly through a pointer. The act of getting to an object via a pointer to it, is called dereferencing the pointer. Pointer variables are defined to point to objects of a specific type so that when the pointer is dereferenced, a typed object is obtained.
Pointers are useful for creating dynamic objects during program execution. Unlike normal (global and local) objects which are allocated storage on the runtime stack, a dynamic object is allocated memory from a different storage area called the heap. Dynamic objects do not obey the normal scope rules.
C Programming Language is the most popular computer language and most used programming language till now. It is very simple and elegant language. This lecture series will give you basic concepts of structured programming language with C.
Python Session - 3
Escape Sequence
Data Types
Conversion between data types
Operators
Python Numbers
Python List
Python Tuple
Python Strings
Python Set
Python Dictionary
This set of slides introduces the reader to a subset of the C++ Standard Library called the Standard Template Library (STL). The STL provides a collection of parameterized containers and algorithms, and it is the most successful example of an approach to programming called generic programming. In this presentation, we aim at studying the ideals and concepts of the STL by re-implementing small parts of the library. Specifically, we first show how we can discover requirements on types in order to devise generic algorithms. Then, we focus on how to make algorithms independent of containers through the pivotal abstraction of iterators. To this end, we replicate the standard algorithm for finding the minimum in a sequence (min_element), which we subsequently match with a custom forward iterator over intrusive linked lists of integers. Finally, we see how function objects can be used to customize containers and algorithms alike. This allows us to deepen our understanding of ordering relations, and, in particular, to introduce the concept of strict weak orderings.
This set of slides introduces the reader to the concept of regular types, i.e., user-defined types whose semantics closely resembles that of built-in types. The notion of regular types proved crucial for the development of the C++ Standard Template Library, and it is currently employed in next-gen C++ libraries such as Eric Niebler's range-v3. The presentation serves as a gentle introduction to the topic, and discusses which requirements must be satisfied for a type to be regular. In particular, the concept of equality-preserving copy and assignment is presented, as well as how to define ordering relations that satisfy the requirements of strictness, transitivity and comparability (i.e., that adhere to the trichotomy law).
This set of slides introduces the reader to the concept of resource wrappers, i.e., classes that are responsible for the correct handling of resources of some kind (e.g., memory). In particular, the presentation discusses the design and implementation of a simplified version of std::vector for the specific case of integer elements. In this regard, we first discuss the fundamental role of destructors as a deterministic, general-purpose undo mechanism. Second, we notice that providing an explicit destructor entails the need of a consequent explicit implementation for the copy constructor and copy assignment operator. We conclude with the formulation of the so-called "rule of three".
This set of slides introduces the reader to the basics of memory management in C++ (with elements of C++11 and C++14). Specifically, after presenting the essential idea of memory segmentation, the presentation contrasts automatic and dynamic objects. To this extent the critical issue of memory leaks is introduced. It follows a discussion on the more advanced topics, such as owning and non-owning (i.e., observer) pointers, as well as dynamic arrays and structures.
This set of slides introduces the reader to the concept of operator overloading for user-defined types in C++ (with elements of C++11 and C++14). The exemplary case of the complex class is introduced. It follows a discussion on how to implement mixed-mode arithmetic, which requires mixing member and non-member operator functions. Moreover, the technical tool of friend functions and access functions is discussed.
An introduction to pointers and references in C++ (with elements of C++11 and C++14). The presentation introduces the readers to the concepts of pointers and references through the pragmatic need of writing a swap function between integers. Generic programming notions (e.g., type constructors) are adopted when useful for the explanation.
Spring MVC - Wiring the different layersIlio Catallo
Β
The presentation focuses on the problem of wiring the different layers of a Spring MVC Web application. More precisely, the presentation explains how to wire the presentation layer (made of Spring MVC controllers) with the service and persistence objects. To this end, the slides first explain how to create the so called back-end (a.k.a. root) container, which will host the persistence and the service objects. Second, the @Repository and @Service annotations are introduced, which permit the framework to auto-discover the application beans. Finally, it is discussed how to wire such beans, through the usage of either the Spring-specific @Autowired annotation or the JEE @Inject annotation.
This set of slides introduces the basic concepts of Java development. First, the difference between Java as the programming language and Java as a platform is stated. Then, the different Java platforms are presented, with a particular interest in Java Standard Edition and Java Enterprise Edition. With respect to the latter, the roles and differences between the many JEE containers are discussed.
How to process request parameters with the Spring MVC framework. Namely, the presentation tackles the three primary concerns when dealing with request parameters: data binding, data buffering and data validation. To this end, the Bean Validation API (JSR-303) is discussed, and the concept of MessageSource for localized error messages is introduced. Moreover, The Post/Redirect/Get (PRG) pattern is presented along with a possible implementation strategy.
An introduction to the basics of the Spring MVC Web framework. The concepts of front controller, controller (handler), model and view are introduced. The whole processing pipeline is discussed, with an in-depth description of the HandlerMapping and ViewResolver strategy interfaces. The alternative representations of the Model (Map, Model and ModelMap) are presented.
This set of slides deals with the problem of building robust Web applications by isolating different areas of concern into different layers. The typical four-layer architecture is presented (consisting of the presentation, service and persistence layer, as well as of the domain model) along with an in-depth discussion on the role and responsibilities of each single layer.
Introduzione al concetto di oggetto nel modello della memoria del C++ e ai suoi possibile tempi di vita (temporaneo, automatico, dinamico, ...). Relazione tra il tempo di vita e la visibilitΓ (scope) di un oggetto. Gestione degli oggetti dinamici per tipi primitivi, strutture e array mediante l'utilizzo di puntatori (raw pointers).
Introduzione agli Array in C++. Argomenti trattati: decadimento a puntatore di un array; conseguenze del meccanismo di decadimento sul passaggio di array a funzioni; array multidimensionali e il concetto di puntatore ad array; come passare array multidimensionali a funzioni; gli iteratori come generalizzazione di un puntatore ad elemento di un array ed una breve scorsa di come usare gli iteratori con gli algoritmi standard (e.g., std::copy) del C++.
Introduzione ai puntatori e ai riferimenti in C++. Viene presentato il problema dello swap, come esempio motivante per l'introduzione della semantica di riferimento. Si procede con l'introduzione del concetto di puntatore, a cui segue una spiegazione dei basilare operatori di referenziazione e dereferenziazione. Il problema dello swap viene risolto mediante puntatori. Si procede con l'introduzione dei riferimenti, come alias di variabili esistenti. Il problema dello swap viene in ultimo risolto mediante riferimenti.
An introduction to the Java Persistence API 2.x (JPA). Namely, this set of slides first introduces the problem of impedance mismatch between the object model and the relation model. Then, the EntityManager's public interface is discussed, together with the parallelism between a persistence context and a L1 cache. The issue of encapsulating the different application's use cases (which are exposed by the service objects) is solved by means of the @Transactional annotation, which provides a declarative way of demarcating the application's transactional boundaries. It follows an in-depth explanation on how to integrate a local, container-managed EntityManager within an existing Spring MVC application, so as to correctly support the propagation of the persistence context throughout the different beans involved in the same transaction. We then turn our attention to the problem of mapping relationships, thus introducing the @OneToMany, @ManyToMany and @OneToOne annotations. The additional topics of how to cascade operations and how to support lazy loading are covered as well. The presentation concludes with a discussion on how to use both the Criteria and Query API (and JPQL) to query the underlying database.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
Β
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Welocme to ViralQR, your best QR code generator.ViralQR
Β
Welcome to ViralQR, your best QR code generator available on the market!
At ViralQR, we design static and dynamic QR codes. Our mission is to make business operations easier and customer engagement more powerful through the use of QR technology. Be it a small-scale business or a huge enterprise, our easy-to-use platform provides multiple choices that can be tailored according to your company's branding and marketing strategies.
Our Vision
We are here to make the process of creating QR codes easy and smooth, thus enhancing customer interaction and making business more fluid. We very strongly believe in the ability of QR codes to change the world for businesses in their interaction with customers and are set on making that technology accessible and usable far and wide.
Our Achievements
Ever since its inception, we have successfully served many clients by offering QR codes in their marketing, service delivery, and collection of feedback across various industries. Our platform has been recognized for its ease of use and amazing features, which helped a business to make QR codes.
Our Services
At ViralQR, here is a comprehensive suite of services that caters to your very needs:
Static QR Codes: Create free static QR codes. These QR codes are able to store significant information such as URLs, vCards, plain text, emails and SMS, Wi-Fi credentials, and Bitcoin addresses.
Dynamic QR codes: These also have all the advanced features but are subscription-based. They can directly link to PDF files, images, micro-landing pages, social accounts, review forms, business pages, and applications. In addition, they can be branded with CTAs, frames, patterns, colors, and logos to enhance your branding.
Pricing and Packages
Additionally, there is a 14-day free offer to ViralQR, which is an exceptional opportunity for new users to take a feel of this platform. One can easily subscribe from there and experience the full dynamic of using QR codes. The subscription plans are not only meant for business; they are priced very flexibly so that literally every business could afford to benefit from our service.
Why choose us?
ViralQR will provide services for marketing, advertising, catering, retail, and the like. The QR codes can be posted on fliers, packaging, merchandise, and banners, as well as to substitute for cash and cards in a restaurant or coffee shop. With QR codes integrated into your business, improve customer engagement and streamline operations.
Comprehensive Analytics
Subscribers of ViralQR receive detailed analytics and tracking tools in light of having a view of the core values of QR code performance. Our analytics dashboard shows aggregate views and unique views, as well as detailed information about each impression, including time, device, browser, and estimated location by city and country.
So, thank you for choosing ViralQR; we have an offer of nothing but the best in terms of QR code services to meet business diversity!
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilotβ’UiPathCommunity
Β
In questo evento online gratuito, organizzato dalla Community Italiana di UiPath, potrai esplorare le nuove funzionalitΓ di Autopilot, il tool che integra l'Intelligenza Artificiale nei processi di sviluppo e utilizzo delle Automazioni.
π Vedremo insieme alcuni esempi dell'utilizzo di Autopilot in diversi tool della Suite UiPath:
Autopilot per Studio Web
Autopilot per Studio
Autopilot per Apps
Clipboard AI
GenAI applicata alla Document Understanding
π¨βπ«π¨βπ» Speakers:
Stefano Negro, UiPath MVPx3, RPA Tech Lead @ BSP Consultant
Flavio Martinelli, UiPath MVP 2023, Technical Account Manager @UiPath
Andrei Tasca, RPA Solutions Team Lead @NTT Data
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Β
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
Β
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more βmechanicalβ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Β
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navyβs DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATOβs (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Β
Are you looking to streamline your workflows and boost your projectsβ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, youβre in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part βEssentials of Automationβ series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Hereβs what youβll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
Weβll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Donβt miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Β
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Β
Monitoring and observability arenβt traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current companyβs observability stack.
While the dev and ops silo continues to crumbleβ¦.many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
Β
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties β USA
Expansion of bot farms β how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks β Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
PHP Frameworks: I want to break free (IPC Berlin 2024)Ralf Eggert
Β
In this presentation, we examine the challenges and limitations of relying too heavily on PHP frameworks in web development. We discuss the history of PHP and its frameworks to understand how this dependence has evolved. The focus will be on providing concrete tips and strategies to reduce reliance on these frameworks, based on real-world examples and practical considerations. The goal is to equip developers with the skills and knowledge to create more flexible and future-proof web applications. We'll explore the importance of maintaining autonomy in a rapidly changing tech landscape and how to make informed decisions in PHP development.
This talk is aimed at encouraging a more independent approach to using PHP frameworks, moving towards a more flexible and future-proof approach to PHP development.
2. Outline
β’ Arrays of arrays
β’ Arrays of arrays vs. pointers
β’ Pointer arithme4c
β’ Arrays of arrays vs. func4ons
β’ The array of arrays type
β’ Bibliography
7. Type aliases
C++ supports type aliases, i.e., new names for previously deο¬ned
types1
using integer = int;
integer a = 5; // the same as: int a = 5
1
Star'ng from C++11, type aliases can be introduced by means of the using keyword (in addi'on to the already
available typedef keyword)
8. Type aliases for array types
We can introduce type aliases for array types as well.
For instance, let us introduce a type alias for the type int[4]
using int4 = int[4];
9. Type aliases for array types
We can now deο¬ne numbers in terms of the type alias int4
using int4 = int[4];
int4 numbers = {1, 7, 13, 10};
10. Can we now take advantage of our newly-deο¬ned alias to deο¬ne an
array of, e.g., 3 elements of type int4?
16. Ini$alizing an array
We know that arrays can be ini1alized using an ini#alizer list
int numbers[4] = {1, 7, 13, 10};
17. Ini$alizing an array
In case of numbers, the ini.alizer list is composed of int values
// 1 is a int, 7 is a int, ...
int numbers[4] = {1, 7, 13, 10};
18. Ini$alizing an array of arrays
In case of m, the ini.alizer list is composed of int4 values
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2}, // {1, 7, 14, 2} is an int4
{8, 16, 12, 10}, // {8, 16, 12, 10} is an int4
{27, 32, 5, 15} }; // {27, 32, 5, 15} is an int4
19. Accessing inner elements
It would be convenient to be able to access inner elements in m
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
20. Accessing inner elements
For example, being able to access the element in (2, 1)
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
21. Accessing inner elements
In order to do so, it is suο¬cient to specify the right amount of
indices (as many as the number of dimensions)
m[2][1]
22. Accessing inner elements
In order to do so, it is suο¬cient to specify the right amount of
indices (as many as the number of dimensions)
m[2][1] β {27, 32, 5, 15}[1]
23. Accessing inner elements
In order to do so, it is suο¬cient to specify the right amount of
indices (as many as the number of dimensions)
m[2][1] β {27, 32, 5, 15}[1] β 32
27. Mul$dimensional arrays
For common arrays, elements are addressed by specifying one
index
βββββ¬ββββ¬ββββ¬ββββ
β β β β β
βββββ΄ββββ΄ββββ΄ββββ
β²
β
i
28. Mul$dimensional arrays
For mul(dimensional arrays, each element is iden(ο¬ed by a tuple of
indexes (as many as the number of dimensions)
βββββ¬ββββ¬ββββ¬ββββ
β β β β β
βββββΌββββΌββββΌββββ€
β β β β β
βββββΌββββΌββββΌββββ€
β β β β βββββ i
βββββ΄ββββ΄ββββ΄ββββ
β²
β
j
29. Arrays of arrays
C++ does not provide proper mul1dimensional arrays. Instead,
mul1dimensional arrays are approximated as arrays of arrays
30. Memory layout
Since mul*dim. arrays are approximated as arrays of arrays, it
follows that elements are organized in memory as a sequence
m[0] m[1] m[2]
ββββββββββββββββΆββββββββββββββΆβββββββββββββββΆ
βββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ¬ββββ
m: β β β β β β β β β β β β β int4[3]
βββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ΄ββββ
32. Pointer to ο¬rst element
Assume we want to store the address of the ο¬rst element of m
// {1, 7, 14, 2} is the 1st element
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
33. Pointer to ο¬rst element
We start by no,cing that the element type of m is int4
int4 m[3] = { {1, 7, 14, 2}, // {1, 7, 14, 2} is an int4
{8, 16, 12, 10}, // {8, 16, 12, 10} is an int4
{27, 32, 5, 15} }; // {27, 32, 5, 15} is an int4
34. Pointer to ο¬rst element
Since the element type is equal to int4, a pointer2
to any element
in the array has to be of type int4*
using int4 = int[4];
int4* first = ...
2
The int4 type alias provides a convenient way to introduce pointers to arrays. Without the intermediate type alias,
one would deο¬ne first to be of type int(*)[4], which is arguably less readable
35. What to write on the RHS?
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
int4* first = ???
36. What to write on the RHS?
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
int4* first = &m[0]; // the address of {1, 7, 14, 2}
37. Pointer decay
As with any array, pointer decay can be used
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
// array-to-pointer decay (int4[3] β int4*)
int4* first = m;
40. Pointer arithme,c
Given that arrays of arrays are only a par1cular case of arrays,
pointer arithme,c can be applied on them without any special
considera1on
41. Pointer arithme,c: addi,on
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
int4* first = m; // ptr to {1, 7, 14, 2}
int4* second = m + 1; // ptr to {8, 16, 12, 10}
int4* third = m + 2; // ptr to {27, 32, 5, 15}
42. Pointer arithme,c
No#ce that pointer arithme#c allows moving between the rows of
our 2-dimensional array m
int4* first = m; // ptr to {1, 7, 14, 2}
int4* second = m + 1; // ptr to {8, 16, 12, 10}
int4* third = m + 2; // ptr to {27, 32, 5, 15}
43. Deriving the indexing operator
Let us now try to reduce inner element access to a sequence of
pointer arithme,c opera,ons
44. Deriving the indexing operator
To this end, let us consider the following expression:
m[2][1]
45. Deriving the indexing operator
By replacing [1] with its deο¬ni3on we obtain:
m[2][1] β *(m[2] + 1)
46. Deriving the indexing operator
If we do the same for [2] we obtain:
m[2][1] β *(m[2] + 1) β *(*(m + 2) + 1)
47. Indexing operator on arrays of arrays
Accessing inner elements of a array of arrays is therefore s2ll
deο¬ned in terms of pointer arithme,c
Given an array of arrays m, and a pair of indexes i and j, the
opera3on a[i][j] is implemented as *(*(m + i) + j)
49. The sum_int func)on
Assume we would like to write a func3on named sum_int, which
computes the summa3on of all the elements in a 2-dimensional
array
50. What we know
β’ We can model 2-dimensional arrays as arrays of arrays
β’ Arrays of arrays follow the same rules as normal arrays
β’ We cannot pass arrays by value
β’ The common workaround is to design func>ons that accept a
pointer to the 1st
element, together with the array size
51. An interface for sum_int
As a ο¬rst step, let us write sum_int so that it works properly when
m is fed as an input
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
53. An interface for sum_int
int sum_int(int4* first, std::size_t n);
54. An interface for sum_int
Since we want sum_int to work with m, we impose first to be of
type int4
int sum_int(int4* first, std::size_t n);
55. An interface for sum_int
Hence, sum_int can only work with 2-dimensional arrays of
exactly 4 columns
int sum_int(int4* first, std::size_t n);
56. An interface for sum_int
int sum_int(int4* first, std::size_t n);
β’ The number of rows is determined by the parameter n
β’ The number of columns is ο¬xed by the type of first (int4)
57. An interface for sum_int
If we need to work with 2-dimensional arrays of, e.g., 5 columns,
we need to write a new func(on4
int sum_int(int4* first, std::size_t n);
int sum_int5(int5* first, std::size_t n);
4
This can be automated by using a func%on template
58. sum_int β sum_int4
In light of this, let us rename sum_int as sum_int4
int sum_int4(int4* first, std::size_t n);
59. Implemen'ng sum_int4
int sum_int4(int4* first, std::size_t n) {
int sum = 0;
for (std::size_t i = 0; i < n; ++i)
for (std::size_t j = 0; j < 4; ++j)
sum += ???
return sum;
}
60. Implemen'ng sum_int4
int sum_int4(int4* first, std::size_t n) {
int sum = 0;
for (std::size_t i = 0; i < n; ++i)
for (std::size_t j = 0; j < 4; ++j)
sum += *(*(first + i) + j);
return sum;
}
61. Implemen'ng sum_int4
int sum_int4(int4* first, std::size_t n) {
int sum = 0;
for (std::size_t i = 0; i < n; ++i)
for (std::size_t j = 0; j < 4; ++j)
sum += first[i][j];
return sum;
}
62. Invoking sum_int4
int main() {
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
int r = sum_int4(???, ???);
std::cout << "the elements sum up to " << r;
}
63. Invoking sum_int4
int main() {
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
int r = sum_int4(m, 3);
std::cout << "the elements sum up to " << r;
}
65. The int4 type alias
Up to now, we took advantage of the int4 type alias for the
deο¬ni7on of m
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
66. The int4 type alias
We did so in order to stress the true nature of mul1dimensional
arrays in C++
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
67. The data type of m
A"er introducing int4, we can say that m is of type int4[3]
(i.e., an array of 3 elements of type int4)
using int4 = int[4];
int4 m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
68. The data type of m
However, one could wonder how to express the data type of m
without introducing the int4 type alias
??? m[3] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
69. The data type of m
This amounts to asking what is the result of applying the [3] type
constructor on int[4]
70. Applying [3] on int
Construct a type "array of 3 elements of type int"
Input type int
Type constructor: [3]
Output type: int[3]
71. Applying [3] on int[4]
Construct a type "array of 3 elements of type int[4]"
Input type: int[4]
Type constructor: [3]
Output type: int[3][4]
72. The data type of m
Therefore, we conclude that m is of type int[3][4]
int m[3][4] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
73. Arrays of arrays
The common C++ syntax for deο¬ning arrays of arrays gives the
illusion of working with mul;dimensional arrays
int m[3][4] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
74. Arrays of arrays
However - though the syntax would suggest otherwise - the
element type of m is s8ll int[4], not int
int m[3][4] = { {1, 7, 14, 2},
{8, 16, 12, 10},
{27, 32, 5, 15} };
75. The alterna*ve signature
As with normal arrays, C++ admits func6on signatures that may
appear more natural when dealing with mul6dimensional arrays
78. The alterna*ve signature
int sum_int4(int m[][4], std::size_t n) {
int sum = 0;
for (std::size_t i = 0; i < n; ++i)
for (std::size_t j = 0; j < 4; ++j)
sum += m[i][j];
return sum;
}
80. Bibliography
β’ S.B. Lippman et al., C++ Primer (5th
Ed.)
β’ B. Stroustrup, The C++ Programming Language (4th
Ed.)
β’ StackOverο¬ow FAQ, "How do I use arrays in C++?"