SlideShare a Scribd company logo
Lecture
ON
Applications of Strings & Pointers
V.Radhesyam
Assistant professor
Department of IT:VRSEC
Radhesyam.V
Array of Strings
1. #include <stdio.h>
2. int main()
3. {
4. char charr[7][10] = {"sun","mon","tue","wed","thu","fri","sat"};
5. int i;
6. for(i=0;i<7;i++)
7. printf("%sn",charr[i]);
8. return 0;
9. }
2
Output:
sun
mon
tue
wed
thu
fri
sat
Radhesyam.V
Array of Strings
1. #include <stdio.h>
2. Void main()
3. {
4. char charr[7][10];
5. int i;
6. printf("enter string");
7. for(i=0;i<7;i++)
8. scanf("%s",charr[i]);
9. printf("string is ");
10. for(i=0;i<7;i++)
11. printf("%sn",charr[i]);
12. }
3
Maximum no of strings
Maximum string length
Radhesyam.V
Pointer arithmetic
4
1. void main()
2. {
3. int first, second, *p, *q, sum,sub,mul,di;
4. printf("Enter two integers n");
5. scanf("%d%d", &first, &second);
6. p = &first;
7. q = &second;
8. sum = *p + *q;
9. sub = *p - *q;
10.mul = (*p) * (*q);
11.di = (*p) /(*q);
12.printf("Sum of the numbers = %dn", sum);
13.printf("Sub of the numbers = %dn", sub);
14.printf("mul of the numbers = %dn", mul);
15.printf("div of the numbers = %dn", di);
16.}
Radhesyam.V
Double Pointer
5
Radhesyam.V
Double pointer Program
6
1. Void main()
2. {
3. int var = 120;
4. int *varptr = &var;
5. int **doubleptr = &varptr;
6. printf("Value of var = %dn", var );
7. printf("Value of var pointer = %dn", *varptr );
8. printf("Value of double pointer = %dn", **doubleptr);
9. printf("Address of var = %pn", &var );
10. printf("Address of var pointer = %pn", &varptr );
11. printf("Value in var pointer = %pn", varptr );
12. printf("Address of double pointer = %pn", *doubleptr);
13. printf("Value in double pointer = %pn", doubleptr);
14. }
Output:
Value of var = 120
Value of var pointer = 120
Value of double pointer = 120
Address of var = 0x7ffe25192bfc
Address of var pointer = 0x7ffe25192c00
Value in var pointer = 0x7ffe25192bfc
Address of double pointer = 0x7ffe25192bfc
Value in double pointer = 0x7ffe25192c00
Radhesyam.V
Scanf vs gets
7
Scanf() Gets()
scanf() function can read different
data types.
get() function will only get character
string data.
scanf() function takes the format
string and list of addresses of
variables. e.g. scanf(“%d”,
&number);
get() function takes the name of the
variable to store the received value.
e.g. gets(name);
Read multiple values One string
Scanf () reads input until it
encounters whitespace, newline or
End Of File (EOF)
gets () reads input until it encounters
newline or End Of File (EOF)
Radhesyam.V
Fibonacci Series Using Recursion
1. int fib(int n)
2. {
3. if (n <= 1)
4. return n;
5. return fib(n-1) + fib(n-2);
6. }
7. int main ()
8. {
9. int n = 9;
10. printf("%d", fib(n));
11. getchar();
12. return 0;
13. }
8
Radhesyam.V
Ceil()
#include <stdio.h>
#include <math.h>
int main()
{
double num = 8.33;
int result;
result = ceil(num);
printf("Ceiling integer of %.2f = %d", num, result);
return 0;
}
9
Output:
Ceiling integer of 8.33 = 9
Radhesyam.V
Floor()
#include <stdio.h>
#include <math.h>
int main()
{ double num = -8.33;
int result;
result = floor(num);
printf("Floor integer of %.2f = %d", num, result);
return 0;
}
10
Output:
Floor integer of -8.33 = -9

More Related Content

PPTX
Looping statements in C
PPTX
Call by value and call by reference in java
PPSX
Nested loops
PPT
File handling in c
PPTX
Strings in C language
PPTX
Dynamic memory allocation in c
PPTX
Pointers in C Programming
PPTX
This pointer
Looping statements in C
Call by value and call by reference in java
Nested loops
File handling in c
Strings in C language
Dynamic memory allocation in c
Pointers in C Programming
This pointer

What's hot (20)

PPTX
Dynamic memory allocation
PPTX
Stack using Array
PPTX
Access specifier
DOC
Arrays and Strings
DOC
Difference between structure and union
PPTX
Pointer in c
PPTX
Constructor in java
ODP
Python Modules
PPTX
Ppt on Linked list,stack,queue
PPTX
File in C language
PPT
C++ Arrays
PPTX
Functions in c language
PPTX
Functions in c
PPTX
Switch Case in C Programming
PPT
Memory allocation in c
PDF
Operator overloading
PPTX
Array in c++
PPTX
Combinational circuits
PPTX
User defined functions in C
Dynamic memory allocation
Stack using Array
Access specifier
Arrays and Strings
Difference between structure and union
Pointer in c
Constructor in java
Python Modules
Ppt on Linked list,stack,queue
File in C language
C++ Arrays
Functions in c language
Functions in c
Switch Case in C Programming
Memory allocation in c
Operator overloading
Array in c++
Combinational circuits
User defined functions in C
Ad

Similar to Array strings (20)

DOCX
string , pointer
PPTX
Arrays
PPSX
Concepts of C [Module 2]
DOCX
C lab manaual
PPTX
PDF
The solution manual of programming in ansi by Robin
PPTX
Lexical Analysis and Parsing
PPTX
3. chapter ii
DOCX
PPTX
Introduction to Basic C programming 02
DOCX
DOCX
Write a program to check a given number is prime or not
PPTX
Twitter Author Prediction from Tweets using Bayesian Network
PPT
Unit3 C
PPT
Chapter 6 arrays part-1
PPTX
Input output functions
PDF
C program
PPTX
Algoritmos e Estruturas de Dados - Pointers
PPTX
C_Arrays.pptx
PDF
The solution manual of c by robin
string , pointer
Arrays
Concepts of C [Module 2]
C lab manaual
The solution manual of programming in ansi by Robin
Lexical Analysis and Parsing
3. chapter ii
Introduction to Basic C programming 02
Write a program to check a given number is prime or not
Twitter Author Prediction from Tweets using Bayesian Network
Unit3 C
Chapter 6 arrays part-1
Input output functions
C program
Algoritmos e Estruturas de Dados - Pointers
C_Arrays.pptx
The solution manual of c by robin
Ad

More from Radhe Syam (6)

PPT
DS.ppt
DOCX
week4_python.docx
DOCX
Pradunma daa
PPT
Searching&amp;sorting
PPT
Structures
DOC
Algorithms and tools for point cloud generation
DS.ppt
week4_python.docx
Pradunma daa
Searching&amp;sorting
Structures
Algorithms and tools for point cloud generation

Recently uploaded (20)

PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPT
introduction to datamining and warehousing
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PPTX
UNIT - 3 Total quality Management .pptx
PPTX
Fundamentals of Mechanical Engineering.pptx
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
PPTX
Current and future trends in Computer Vision.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Artificial Intelligence
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
III.4.1.2_The_Space_Environment.p pdffdf
introduction to datamining and warehousing
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
UNIT - 3 Total quality Management .pptx
Fundamentals of Mechanical Engineering.pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
Integrating Fractal Dimension and Time Series Analysis for Optimized Hyperspe...
Categorization of Factors Affecting Classification Algorithms Selection
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
86236642-Electric-Loco-Shed.pdf jfkduklg
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Fundamentals of safety and accident prevention -final (1).pptx
UNIT no 1 INTRODUCTION TO DBMS NOTES.pdf
Current and future trends in Computer Vision.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Artificial Intelligence

Array strings

  • 1. Lecture ON Applications of Strings & Pointers V.Radhesyam Assistant professor Department of IT:VRSEC
  • 2. Radhesyam.V Array of Strings 1. #include <stdio.h> 2. int main() 3. { 4. char charr[7][10] = {"sun","mon","tue","wed","thu","fri","sat"}; 5. int i; 6. for(i=0;i<7;i++) 7. printf("%sn",charr[i]); 8. return 0; 9. } 2 Output: sun mon tue wed thu fri sat
  • 3. Radhesyam.V Array of Strings 1. #include <stdio.h> 2. Void main() 3. { 4. char charr[7][10]; 5. int i; 6. printf("enter string"); 7. for(i=0;i<7;i++) 8. scanf("%s",charr[i]); 9. printf("string is "); 10. for(i=0;i<7;i++) 11. printf("%sn",charr[i]); 12. } 3 Maximum no of strings Maximum string length
  • 4. Radhesyam.V Pointer arithmetic 4 1. void main() 2. { 3. int first, second, *p, *q, sum,sub,mul,di; 4. printf("Enter two integers n"); 5. scanf("%d%d", &first, &second); 6. p = &first; 7. q = &second; 8. sum = *p + *q; 9. sub = *p - *q; 10.mul = (*p) * (*q); 11.di = (*p) /(*q); 12.printf("Sum of the numbers = %dn", sum); 13.printf("Sub of the numbers = %dn", sub); 14.printf("mul of the numbers = %dn", mul); 15.printf("div of the numbers = %dn", di); 16.}
  • 6. Radhesyam.V Double pointer Program 6 1. Void main() 2. { 3. int var = 120; 4. int *varptr = &var; 5. int **doubleptr = &varptr; 6. printf("Value of var = %dn", var ); 7. printf("Value of var pointer = %dn", *varptr ); 8. printf("Value of double pointer = %dn", **doubleptr); 9. printf("Address of var = %pn", &var ); 10. printf("Address of var pointer = %pn", &varptr ); 11. printf("Value in var pointer = %pn", varptr ); 12. printf("Address of double pointer = %pn", *doubleptr); 13. printf("Value in double pointer = %pn", doubleptr); 14. } Output: Value of var = 120 Value of var pointer = 120 Value of double pointer = 120 Address of var = 0x7ffe25192bfc Address of var pointer = 0x7ffe25192c00 Value in var pointer = 0x7ffe25192bfc Address of double pointer = 0x7ffe25192bfc Value in double pointer = 0x7ffe25192c00
  • 7. Radhesyam.V Scanf vs gets 7 Scanf() Gets() scanf() function can read different data types. get() function will only get character string data. scanf() function takes the format string and list of addresses of variables. e.g. scanf(“%d”, &number); get() function takes the name of the variable to store the received value. e.g. gets(name); Read multiple values One string Scanf () reads input until it encounters whitespace, newline or End Of File (EOF) gets () reads input until it encounters newline or End Of File (EOF)
  • 8. Radhesyam.V Fibonacci Series Using Recursion 1. int fib(int n) 2. { 3. if (n <= 1) 4. return n; 5. return fib(n-1) + fib(n-2); 6. } 7. int main () 8. { 9. int n = 9; 10. printf("%d", fib(n)); 11. getchar(); 12. return 0; 13. } 8
  • 9. Radhesyam.V Ceil() #include <stdio.h> #include <math.h> int main() { double num = 8.33; int result; result = ceil(num); printf("Ceiling integer of %.2f = %d", num, result); return 0; } 9 Output: Ceiling integer of 8.33 = 9
  • 10. Radhesyam.V Floor() #include <stdio.h> #include <math.h> int main() { double num = -8.33; int result; result = floor(num); printf("Floor integer of %.2f = %d", num, result); return 0; } 10 Output: Floor integer of -8.33 = -9