it is an array and pointers In this tutorial, you'll learn about the relationship between arrays and pointers in C programming. You will also learn to access array elements using pointers.
Before you learn about the relationship between arrays and pointers, be sure to check these two topics:
In most contexts, array names decay to pointers. In simple words, array names are converted to pointers. That's the reason why you can use pointers to access elements of arrays. However, you should remember that pointers and arrays are not the same.
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.
Asit Bangalore is providing best Programming course "C LANGUAGE" and helped them to take internship program which is helped to get real time exposure and placements in global world. For more details Please visit our website.
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.
Asit Bangalore is providing best Programming course "C LANGUAGE" and helped them to take internship program which is helped to get real time exposure and placements in global world. For more details Please visit our website.
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
At the end of this lecture students should be able to;
Define the C pointers and its usage in computer programming.
Describe pointer declaration and initialization.
Apply C pointers for expressions.
Experiment on pointer operations.
Identify NULL pointer concept.
Experiment on pointer to pointer, pointer arrays, arrays with pointers and functions with pointers.
Apply taught concepts for writing programs.
C++ very good for us jvkbivucyyfuvivucyxtcubobicyxyvinoucyvibivuvuvuviviibivufucuvubibibuvibibbbibibibhibobkvucycuvibibibibobobobobobobobobobibobkgxyvibibihobibibibibibibibibibibibibibibibivibivuvuvuvuvuvbobobohobkbkbobkkbcccvgvgvgctctctctcrctcrcrcrcrcrvtvtvtctcrcrcrcrcrcrcrcrcrcrcrcrcrcrctvfvfcfvfvtcrcrct rvtctvtvtcrcrcrcrcrcrcrcrcrcrcrcrctctcrcrcrcrcrcrcrcrcrcrcrcrvrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrctvtvtvtvtvtvtctvbvvgghhhbbbbbhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhuhhuuuhuuuuuuhuuuuuuuuuuuujtvtvfvtvtvtvtvfvtctvtcctcfctcrcfcfcf f f cccccccccfccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Pointers are among C’s most powerful, yet most difficult concepts to master. Some tasks like dynamic memory allocation done only by using pointers. So it is essential to learn pointers.
Pointers are a type of variable, just like int, double, etc., except instead of storing a value, they store a memory address of another variable.
At the end of this lecture students should be able to;
Define the C pointers and its usage in computer programming.
Describe pointer declaration and initialization.
Apply C pointers for expressions.
Experiment on pointer operations.
Identify NULL pointer concept.
Experiment on pointer to pointer, pointer arrays, arrays with pointers and functions with pointers.
Apply taught concepts for writing programs.
C++ very good for us jvkbivucyyfuvivucyxtcubobicyxyvinoucyvibivuvuvuviviibivufucuvubibibuvibibbbibibibhibobkvucycuvibibibibobobobobobobobobobibobkgxyvibibihobibibibibibibibibibibibibibibibivibivuvuvuvuvuvbobobohobkbkbobkkbcccvgvgvgctctctctcrctcrcrcrcrcrvtvtvtctcrcrcrcrcrcrcrcrcrcrcrcrcrcrctvfvfcfvfvtcrcrct rvtctvtvtcrcrcrcrcrcrcrcrcrcrcrcrctctcrcrcrcrcrcrcrcrcrcrcrcrvrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrcrctvtvtvtvtvtvtctvbvvgghhhbbbbbhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhuhhuuuhuuuuuuhuuuuuuuuuuuujtvtvfvtvtvtvtvfvtctvtcctcfctcrcfcfcf f f cccccccccfccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
In Islam, al-A'raf is a separator realm or borderland between Jannah and Jahannam, inhabited by those who are evenly balanced in their sins and virtues, they are not entirely evil nor are they entirely good. This place may be described as a kind of benevolent purgatory with privation but without suffering. Wikipedia
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
2. Objectives
Be able to use arrays, pointers, and strings in
C programs
Be able to explain the representation of these
data types at the machine level, including
their similarities and differences
Cox Arrays and Pointers 2
3. Cox Arrays and Pointers 3
Arrays in C
No bounds checking!
Allowed – usually causes no obvious error
array[10] may overwrite b
Unlike Java, array size in declaration
int array[10];
int b;
array[0] = 3;
array[9] = 4;
array[10] = 5;
array[-1] = 6;
Compare: C: int array[10];
Java: int[] array = new int[10];
All elements of same type – homogenous
First element (index 0)
Last element (index size - 1)
4. Cox Arrays and Pointers 4
Array Representation
Homogeneous Each element same size – s bytes
An array of m data values is a sequence of ms bytes
Indexing: 0th value at byte s0, 1st value at byte s1, …
m and s are not part of representation
Unlike in some other languages
s known by compiler – usually irrelevant to programmer
m often known by compiler – if not, must be saved by
programmer
a[0]
a[1]
a[2]
0x1000
0x1004
0x1008
int a[3];
5. Cox Arrays and Pointers 5
Array Representation
char c1;
int a[3];
char c2;
int i;
c1
a[0]
a[1]
a[2]
i
0x1000
0x1004
0x1008
0x100C
0x1014
c2
0x1010
Could be optimized by
making these adjacent,
and reducing padding
(by default, not)
Array aligned by
size of elements
6. Cox Arrays and Pointers 6
Array Sizes
What is
sizeof(array[3])?
sizeof(array)?
int array[10];
4
40
returns the size of
an object in bytes
7. Cox Arrays and Pointers 7
Multi-Dimensional Arrays
int matrix[2][3];
matrix[1][0] = 17;
matrix[0][0]
matrix[0][1]
matrix[0][2]
0x1000
0x1004
0x1008
matrix[1][0]
matrix[1][1]
matrix[1][2]
0x100C
0x1010
0x1014
Recall: no bounds checking
What happens when you write:
matrix[0][3] = 42;
“Row Major”
Organization
8. Cox Arrays and Pointers 8
Variable-Length Arrays
int
function(int n)
{
int array[n];
…
New C99 feature: Variable-length arrays
defined within functions
Global arrays must still have fixed (constant) length
9. Cox Arrays and Pointers 9
Memory Addresses
Storage cells are typically viewed as being
byte-sized
Usually the smallest addressable unit of memory
• Few machines can directly address bits individually
Such addresses are sometimes called byte-
addresses
Memory is often accessed as words
Usually a word is the largest unit of memory access
by a single machine instruction
• CLEAR’s word size is 8 bytes (= sizeof(long))
A word-address is simply the byte-address of the
word’s first byte
10. Cox Arrays and Pointers 10
Pointers
Special case of bounded-size natural numbers
Maximum memory limited by processor word-size
232 bytes = 4GB, 264 bytes = 16 exabytes
A pointer is just another kind of value
A basic type in C
int *ptr;
The variable “ptr” stores a pointer to an “int”.
11. Cox Arrays and Pointers 11
Pointer Operations in C
Creation
& variable Returns variable’s memory address
Dereference
* pointer Returns contents stored at address
Indirect assignment
* pointer = val Stores value at address
Of course, still have...
Assignment
pointer = ptr Stores pointer in another variable
12. Cox Arrays and Pointers 12
Using Pointers
int i1;
int i2;
int *ptr1;
int *ptr2;
i1 = 1;
i2 = 2;
ptr1 = &i1;
ptr2 = ptr1;
*ptr1 = 3;
i2 = *ptr2;
i1:
i2:
ptr1:
0x1000
0x1004
0x1008
…
ptr2:
…
0x100C
0x1010
0x1014
1
2
0x1000
0x1000
3
3
13. Cox Arrays and Pointers 13
Using Pointers (cont.)
Type check warning: int_ptr2 is not an int
int1 becomes 8
int int1 = 1036; /* some data to point to */
int int2 = 8;
int *int_ptr1 = &int1; /* get addresses of data */
int *int_ptr2 = &int2;
*int_ptr1 = int_ptr2;
*int_ptr1 = int2;
What happens?
14. Cox Arrays and Pointers 14
Using Pointers (cont.)
Type check warning: *int_ptr2 is not an int *
Changes int_ptr1 – doesn’t change int1
int int1 = 1036; /* some data to point to */
int int2 = 8;
int *int_ptr1 = &int1; /* get addresses of data */
int *int_ptr2 = &int2;
int_ptr1 = *int_ptr2;
int_ptr1 = int_ptr2;
What happens?
15. Cox Arrays and Pointers 15
Pointer Arithmetic
pointer + number pointer – number
E.g., pointer + 1 adds 1 something to a pointer
char *p;
char a;
char b;
p = &a;
p += 1;
int *p;
int a;
int b;
p = &a;
p += 1;
In each, p now points to b
(Assuming compiler doesn’t
reorder variables in memory)
Adds 1*sizeof(char) to
the memory address
Adds 1*sizeof(int) to
the memory address
Pointer arithmetic should be used cautiously
16. Cox Arrays and Pointers 16
A Special Pointer in C
Special constant pointer NULL
Points to no data
Dereferencing illegal – causes segmentation fault
To define, include <stdlib.h> or <stdio.h>
17. Cox Arrays and Pointers 17
Generic Pointers
void *: a “pointer to anything”
Lose all information about what type of thing
is pointed to
Reduces effectiveness of compiler’s type-checking
Can’t use pointer arithmetic
void *p;
int i;
char c;
p = &i;
p = &c;
putchar(*(char *)p);
type cast: tells the compiler to
“change” an object’s type (for type
checking purposes – does not modify
the object in any way)
Dangerous! Sometimes necessary…
18. Cox Arrays and Pointers 18
Pass-by-Reference
void
set_x_and_y(int *x, int *y)
{
*x = 1001;
*y = 1002;
}
void
f(void)
{
int a = 1;
int b = 2;
set_x_and_y(&a, &b);
}
1
2
a
b
x
y
1001
1002
19. Cox Arrays and Pointers 19
Arrays and Pointers
Dirty “secret”:
Array name a pointer to the
initial (0th) array element
a[i] *(a + i)
An array is passed to a function
as a pointer
The array size is lost!
Usually bad style to interchange
arrays and pointers
Avoid pointer arithmetic!
Really int *array
int
foo(int array[],
unsigned int size)
{
… array[size - 1] …
}
int
main(void)
{
int a[10], b[5];
… foo(a, 10)… foo(b, 5) …
}
Must explicitly
pass the size
Passing arrays:
20. Cox Arrays and Pointers 20
Arrays and Pointers
int
foo(int array[],
unsigned int size)
{
…
printf(“%dn”, sizeof(array));
}
int
main(void)
{
int a[10], b[5];
… foo(a, 10)… foo(b, 5) …
printf(“%dn”, sizeof(a));
}
What does this print?
What does this print?
8
40
... because array is really
a pointer
21. Cox Arrays and Pointers 21
Arrays and Pointers
int i;
int array[10];
for (i = 0; i < 10; i++) {
…
array[i] = …;
…
}
int *p;
int array[10];
for (p = array; p < &array[10]; p++) {
…
*p = …;
…
}
These two blocks of code are functionally equivalent
22. Cox Arrays and Pointers 22
Strings
In C, strings are just an array of characters
Terminated with ‘0’ character
Arrays for bounded-length strings
Pointer for constant strings (or unknown length)
char str1[15] = “Hello, world!n”;
char *str2 = “Hello, world!n”;
H e l l o , w l
o r d !n
length
H e l l o , w l
o r d !nterminator
Pascal, Java, …
C, …
C terminator: ’0’
23. Cox Arrays and Pointers 23
String length
Must calculate length:
Provided by standard C library: #include <string.h>
int
strlen(char str[])
{
int len = 0;
while (str[len] != ‘0’)
len++;
return (len);
}
can pass an
array or pointer
Check for
terminator
array access
to pointer!
What is the size
of the array???
24. Pointer to Pointer (char **argv)
Cox Arrays and Pointers 24
Passing arguments to main:
int
main(int argc, char **argv)
{
...
}
an array/vector of
char *
Recall when passing an
array, a pointer to the
first element is passed
size of the argv array/vector
Suppose you run the program this way
UNIX% ./program hello 1 2 3
argc == 5 (five strings on the
command line)
25. Cox Arrays and Pointers 25
char **argv
argv[0]
argv[1]
argv[2]
0x1000
0x1008
0x1010
argv[3]
argv[4]
0x1018
0x1020
“./program”
“hello”
“1”
“2”
“3”
These are strings!!
Not integers!
26. Cox Arrays and Pointers 26
Next Time
Structures and Unions