Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

ECE 263/264

Lab 8
Due: Friday Oct 31
Warm up exerciseswe will discuss the following
Pointer s
Passing pointers to functions
Returning pointers from functions

Arithmetic

Introduction to strings

Run this code below:

#include <stdio.h>
int main()
{
int a[3] = {10, 12, 10};
printf(" a is %d\n", a);
printf(" a+1 is %d\n",a+1);
printf(" a+2 is %d\n",a+2);
printf(" *a is %d\n",*a);
printf(" *(a+1) is %d\n", *(a+1));
printf(" *(a+2) is %d\n", *(a+2));
printf(" address of a[0] is %d\n", &a[0]);
printf(" address of a[1] is %d\n", &a[1]);
printf(" address of a[2] is %d\n", &a[2]);
return 0;
}

Given the following declarations:


char AR[10];
short WW[13];
double M[100];
char *cp; short
*sp; short *sp2;
double *dp;
Suppose:
AR is located at address 500
WW is locates at address

2100 M is located at address


3340
Determine the following:
a) dp after executing dp = &M[5];
b) cp after executing cp = &AR[4];
c) dp after executing dp = M+9;
d) Suppose we execute sp=WW; and then we execute sp = sp+5. Now determine sp
e) Determine sp sp2
After executing sp=&WW[7]; and sp2=&WW[2]

Consider the following declarations:


short T[3] = {6, 17, 3};
short *sp =T;
short x;
a) x = 10 - *sp+1;
b) x = 10 - *(sp+1)
c) x = 10 - *(T+2)
d) X = 10 - *(&T[1])
d) What is *(sp+3)

Lab 8 (this is to be turned in)


Palindrome is a string that is the same as backwards or forwards
otto
ababa
noon
ababbbbaba
In this lab we will work with strings (so we will be using character arrays).
In this lab we will define a char array:
1. Write a function computeLength and call this functionin main to ompute the
length of the string str
2. if the string str is of length 0 the program will terminate
3. Call this function with str1 in main and output your result
Now write a function isPalindrome(str) that returns a 1 if str is a palindrome and 0
otherwise. To get full credit use isReversePrefix in your function
int computeLength(char *str);
int isPalindrome (char *str);

You might also like