0% found this document useful (0 votes)
23 views

Array-String - Pointer

An array allows multiple values of the same type to be stored and accessed using indices. Arrays are declared with a data type followed by the array name and size in square brackets. An example program calculates the average of integers entered by the user and stored in an array. Strings can also be manipulated using arrays of characters. Pointers are special variables that store memory addresses rather than values directly. They can be used to access the location in memory of other variables.

Uploaded by

Nashim Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Array-String - Pointer

An array allows multiple values of the same type to be stored and accessed using indices. Arrays are declared with a data type followed by the array name and size in square brackets. An example program calculates the average of integers entered by the user and stored in an array. Strings can also be manipulated using arrays of characters. Pointers are special variables that store memory addresses rather than values directly. They can be used to access the location in memory of other variables.

Uploaded by

Nashim Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Array

An array is a variable that can store multiple values. For example, if you want to store 100
integers, you can create an array for it.

How to declare an array?


dataType arrayName[arraySize];
int data[100];

Program to find the average of n numbers using arrays

#include <stdio.h>
#include<conio.h>
void main()
{
int marks[10], i, n, sum = 0, average;

printf("Enter number of elements: ");


scanf("%d", &n);

for(i=0; i<n; ++i)


{
printf("Enter number%d: ",i+1);
scanf("%d", &marks[i]);

sum += marks[i];
}

average = sum/n;
printf("Average = %d", average);

getch();
}

Output

Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49
Average = 39

String

#include <stdio.h>
#include<conio.h>

void main()
{
  char s[10];
  int count = 0;

  printf("Input a string\n");
  gets(s);

  while (s[count] != '\0')


    count++;

  printf("Length of the string: %d\n", count);

  getch();
}

output

Computer
Length of string 8

unction Work of Function


strlen() computes string's length
strcpy() copies a string to another
strcat() concatenates(joins) two strings
strcmp() compares two strings
strlwr() converts string to lowercase
strupr() converts string to uppercase
strrev() Reverse the string

Pointer

C Pointers
Pointers (pointer variables) are special variables that are used to store addresses rather than
values.

int* p;

#include <stdio.h>
#include<conio.h>

void main () {

int var1;
char var2[10];

printf("Address of var1 variable: %x\n", &var1 );


printf("Address of var2 variable: %x\n", &var2 );

getch();
}

Output
Address of var1 variable: bff5a400
Address of var2 variable: bff5a3f6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy