SlideShare une entreprise Scribd logo
1  sur  6
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 1
DHANALAKSHMI COLLEGE OF ENGINEERING
Tambaram, Chennai
Department of Computer Science and Engineering
OCS752 INTRODUCTION TO C PROGRAMMING
Year / Sem : IV / VII
2 Marks Q & A
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 2
UNIT – III
STRINGS
Introduction to Strings – Reading and writing a string – String operations (without using built-in string
functions): Length – Compare – Concatenate – Copy – Reverse – Substring – Insertion – Indexing –
Deletion – Replacement – Array of strings – Introduction to Pointers – Pointer operators – Pointer
arithmetic – Exercise programs: To find the frequency of a character in a string – To find the number of
vowels, consonants and white spaces in a given text – Sorting the names
PART – A
1. Define – Strings
Strings or character array is defined as the group of characters, digit and symbols enclosed within a
quote. Strings are always terminated with “0” (NULL) character. The compiler automatically adds “0”
at the end of the strings.
2. What is the use of ‘0’ character?
When declaring character arrays (strings), “0” (NULL) character is automatically added at the end of the
string. The “0‟ character acts as an end of character array.
3. Give an example for initialization of string array. (N/D – 14)
Program for initialization of string array
#include<stdio.h>
void main()
{
char city[9]={'N','E','W','Y','O','R','K'};
printf("%s",city);
}
Output:
NEWYORK
4. List the important string handling functions in C.
The important strings handling functions in C
1) strcat() – concatenates two strings
2) strcmp() – compares two strings
3) strcpy() – copies one string over other
4) strlen() – finds length of a string
5) strrev() – reverse the string
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 3
5. What is the use of strcmp()?
strcmp() function compares two strings to find whether they are same or different. If two strings are
equal, then it returns a zero otherwise numeric difference between the non-matching character.
Syntax: strcmp(string1,string2);
6. Write a C function to compare two strings. (A/M – 18, A/M – 19)
Program to compare two strings using function
#include <stdio.h>
#include <string.h>
void main()
{
char a[100], b[100];
gets(a);
gets(b);
if (strcmp(a,b) == 0)
printf("The strings are equal.n");
else
printf("The strings are not equal.n");
}
Output:
xx xx
The strings are equal
7. What is the use of strlen() and strcat() ?
strlen() function is used to count and return the number of character present in a string.
Syntax: len=strlen(string);
strcat() function is used to concatenate or combine two strings together then forms a new string.
Syntax: strcat(str1,str2);
8. What are strrev() and strcpy() function? Write its syntax.
strrev() function is used to reverse a string. This function takes and returns only one argument.
Syntax: strrev(str);
strncpy() is used to copy some portion of one string to another string.
Syntax: strncpy(str1 , str2 ,4) // It copies first 4 characters of str2 to str1.
9. How strings are represented in C language? (A/M - 10)
Strings in C are represented by arrays of characters. The end of the string is marked with a special
character, the null character, which is simply the character with the value 0. (The null character has no
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 4
relation except in name to the null pointer. In the ASCII character set, the null character is named NUL.)
Ex.: char string1[] = "Hello, world!";
10. Distinguish between string and array.
S. No. String Array
1 String can hold only char data type Array can hold any data type
2
String size can be changed if it is a
character pointer
Array size cannot be changed
3
The last character of string is a null (“0”)
character
The last element of an array is an element
of the specific type
11. What is a Pointer? How a variable is declared to the pointer? (A/M – 13)
Pointer is a variable which holds the address of another variable. A variable can be declared to the
pointer by using the following syntax
Syntax:
data_type *variable_name;
Example:
int *x, a=5;
x=&a;
12. List the pointer operators.
S. No. Operator Meaning Description
1 * Value at Operator Gives values stored at address
2 & Address Operator Gives address of variable
13. What is the output of the following program? (A/M – 15)
main ()
{
int a=8, b=4, c, *p1=&a, *p2=&b;
c=*p1**p2-*p1/ *p2+9;
printf (“%d”,c); }
Output
c: 39
14. When is null pointer used? (A/M – 18)
Null pointer is used to initialize a pointer variable when that pointer variable is not assigned to any valid
memory address.
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 5
15. What is pointer to a pointer?
Pointer to a pointer is a pointer variable points another pointer value. It is mainly used in dynamic
memory allocation. Multiple level of allocation can be accomplished by using pointer to a pointer
variable.
Example:
int *p1, **p2,v=10;
P1=&v; p2=&p1;
Here p2 is a pointer to a pointer.
16. What are the uses of pointer?
Uses of pointers
1) Used to return more than one value to the function
2) More efficient in handling the data in arrays
3) Reduce the length and complexity of the program
4) Allow management of structures which are allocated memory dynamically
17. What will be output of the following program?
#include<stdio.h>
int main()
{
int n=20;
printf(“n %d “, n);
printf(“n %u“, &n);
printf(“n %d “, *(&n));
}
Output
20
1260034844
20
18. What are the possible arithmetic operations on pointers in C language?
Possible arithmetic operations on pointers in C language
1) Increment
2) Decrement
3) Subtraction
4) Comparison
OCS752 − Introduction to C Programming VII SemesterEEE
Dept. of CSE Dhanalakshmi College of Engineering 6
19. What is pointer arithmetic?
One of the uses of pointer is pointer arithmetic. Like an ordinary variable, pointer variable can also be
used in arithmetic expressions. Assume x, y and z are pointer variables, and the values are 10, 20, 30
respectively. Then the following is an example of pointer expression.
Expression Result
C =*y + 10 Value of c is 30
C = *z + *y Value of c is 50
C = *x + 10 + *y Value of c is 40
C = ++*x Value of c is 11
20. List the applications of pointers.
Applications of pointers
1) To implement data structures
2) Dynamic memory allocation
3) To pass arguments by reference
4) To do system level programming where memory addresses are useful

Contenu connexe

Tendances (20)

String c
String cString c
String c
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
cs8251 unit 1 ppt
cs8251 unit 1 pptcs8251 unit 1 ppt
cs8251 unit 1 ppt
 
Function in C
Function in CFunction in C
Function in C
 
Java interface
Java interfaceJava interface
Java interface
 
Arrays In C
Arrays In CArrays In C
Arrays In C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
Unit4
Unit4Unit4
Unit4
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
C Structures And Unions
C  Structures And  UnionsC  Structures And  Unions
C Structures And Unions
 
Programming in c
Programming in cProgramming in c
Programming in c
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
C functions
C functionsC functions
C functions
 
Interface in java
Interface in javaInterface in java
Interface in java
 

Similaire à Ocs752 unit 3

C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptxsamdamfa
 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxKorbanMaheshwari
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptxKorbanMaheshwari
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
Character Arrays and strings in c language
Character Arrays and strings in c languageCharacter Arrays and strings in c language
Character Arrays and strings in c languagemallikavin
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfaroraopticals15
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotesSowri Rajan
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 

Similaire à Ocs752 unit 3 (20)

Array and string
Array and stringArray and string
Array and string
 
Lk module3
Lk module3Lk module3
Lk module3
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Ankita sharma focp
Ankita sharma focpAnkita sharma focp
Ankita sharma focp
 
Unit-IV Strings.pptx
Unit-IV Strings.pptxUnit-IV Strings.pptx
Unit-IV Strings.pptx
 
C programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptxC programming basic concepts of mahi.pptx
C programming basic concepts of mahi.pptx
 
Basic Concepts of C Language.pptx
Basic Concepts of C Language.pptxBasic Concepts of C Language.pptx
Basic Concepts of C Language.pptx
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
CP Handout#8
CP Handout#8CP Handout#8
CP Handout#8
 
Character Arrays and strings in c language
Character Arrays and strings in c languageCharacter Arrays and strings in c language
Character Arrays and strings in c language
 
8
88
8
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Arrays
ArraysArrays
Arrays
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
C++
C++C++
C++
 

Dernier

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Dernier (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Ocs752 unit 3

  • 1. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 1 DHANALAKSHMI COLLEGE OF ENGINEERING Tambaram, Chennai Department of Computer Science and Engineering OCS752 INTRODUCTION TO C PROGRAMMING Year / Sem : IV / VII 2 Marks Q & A
  • 2. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 2 UNIT – III STRINGS Introduction to Strings – Reading and writing a string – String operations (without using built-in string functions): Length – Compare – Concatenate – Copy – Reverse – Substring – Insertion – Indexing – Deletion – Replacement – Array of strings – Introduction to Pointers – Pointer operators – Pointer arithmetic – Exercise programs: To find the frequency of a character in a string – To find the number of vowels, consonants and white spaces in a given text – Sorting the names PART – A 1. Define – Strings Strings or character array is defined as the group of characters, digit and symbols enclosed within a quote. Strings are always terminated with “0” (NULL) character. The compiler automatically adds “0” at the end of the strings. 2. What is the use of ‘0’ character? When declaring character arrays (strings), “0” (NULL) character is automatically added at the end of the string. The “0‟ character acts as an end of character array. 3. Give an example for initialization of string array. (N/D – 14) Program for initialization of string array #include<stdio.h> void main() { char city[9]={'N','E','W','Y','O','R','K'}; printf("%s",city); } Output: NEWYORK 4. List the important string handling functions in C. The important strings handling functions in C 1) strcat() – concatenates two strings 2) strcmp() – compares two strings 3) strcpy() – copies one string over other 4) strlen() – finds length of a string 5) strrev() – reverse the string
  • 3. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 3 5. What is the use of strcmp()? strcmp() function compares two strings to find whether they are same or different. If two strings are equal, then it returns a zero otherwise numeric difference between the non-matching character. Syntax: strcmp(string1,string2); 6. Write a C function to compare two strings. (A/M – 18, A/M – 19) Program to compare two strings using function #include <stdio.h> #include <string.h> void main() { char a[100], b[100]; gets(a); gets(b); if (strcmp(a,b) == 0) printf("The strings are equal.n"); else printf("The strings are not equal.n"); } Output: xx xx The strings are equal 7. What is the use of strlen() and strcat() ? strlen() function is used to count and return the number of character present in a string. Syntax: len=strlen(string); strcat() function is used to concatenate or combine two strings together then forms a new string. Syntax: strcat(str1,str2); 8. What are strrev() and strcpy() function? Write its syntax. strrev() function is used to reverse a string. This function takes and returns only one argument. Syntax: strrev(str); strncpy() is used to copy some portion of one string to another string. Syntax: strncpy(str1 , str2 ,4) // It copies first 4 characters of str2 to str1. 9. How strings are represented in C language? (A/M - 10) Strings in C are represented by arrays of characters. The end of the string is marked with a special character, the null character, which is simply the character with the value 0. (The null character has no
  • 4. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 4 relation except in name to the null pointer. In the ASCII character set, the null character is named NUL.) Ex.: char string1[] = "Hello, world!"; 10. Distinguish between string and array. S. No. String Array 1 String can hold only char data type Array can hold any data type 2 String size can be changed if it is a character pointer Array size cannot be changed 3 The last character of string is a null (“0”) character The last element of an array is an element of the specific type 11. What is a Pointer? How a variable is declared to the pointer? (A/M – 13) Pointer is a variable which holds the address of another variable. A variable can be declared to the pointer by using the following syntax Syntax: data_type *variable_name; Example: int *x, a=5; x=&a; 12. List the pointer operators. S. No. Operator Meaning Description 1 * Value at Operator Gives values stored at address 2 & Address Operator Gives address of variable 13. What is the output of the following program? (A/M – 15) main () { int a=8, b=4, c, *p1=&a, *p2=&b; c=*p1**p2-*p1/ *p2+9; printf (“%d”,c); } Output c: 39 14. When is null pointer used? (A/M – 18) Null pointer is used to initialize a pointer variable when that pointer variable is not assigned to any valid memory address.
  • 5. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 5 15. What is pointer to a pointer? Pointer to a pointer is a pointer variable points another pointer value. It is mainly used in dynamic memory allocation. Multiple level of allocation can be accomplished by using pointer to a pointer variable. Example: int *p1, **p2,v=10; P1=&v; p2=&p1; Here p2 is a pointer to a pointer. 16. What are the uses of pointer? Uses of pointers 1) Used to return more than one value to the function 2) More efficient in handling the data in arrays 3) Reduce the length and complexity of the program 4) Allow management of structures which are allocated memory dynamically 17. What will be output of the following program? #include<stdio.h> int main() { int n=20; printf(“n %d “, n); printf(“n %u“, &n); printf(“n %d “, *(&n)); } Output 20 1260034844 20 18. What are the possible arithmetic operations on pointers in C language? Possible arithmetic operations on pointers in C language 1) Increment 2) Decrement 3) Subtraction 4) Comparison
  • 6. OCS752 − Introduction to C Programming VII SemesterEEE Dept. of CSE Dhanalakshmi College of Engineering 6 19. What is pointer arithmetic? One of the uses of pointer is pointer arithmetic. Like an ordinary variable, pointer variable can also be used in arithmetic expressions. Assume x, y and z are pointer variables, and the values are 10, 20, 30 respectively. Then the following is an example of pointer expression. Expression Result C =*y + 10 Value of c is 30 C = *z + *y Value of c is 50 C = *x + 10 + *y Value of c is 40 C = ++*x Value of c is 11 20. List the applications of pointers. Applications of pointers 1) To implement data structures 2) Dynamic memory allocation 3) To pass arguments by reference 4) To do system level programming where memory addresses are useful