SlideShare a Scribd company logo
What is the difference between a string copy (strcpy) and a memory copy 
(memcpy)? When should each be used? 
The strcpy() function is designed to work exclusively with strings. It copies 
each byte of the source string to the destination string and stops when the 
terminating null character (0) has been moved. On the other hand, the memcpy() 
function is designed to work with any type of data. 
Because not all data ends with a null character, you must provide the memcpy() 
function with the number of bytes you want to copy from the source to the 
destination. The following program shows examples of both the strcpy() and the 
memcpy() functions: 
. How can I remove the trailing spaces from a string? 
The C language does not provide a standard function that removes trailing spaces 
from a string. It is easy, however, to build your own function to do just this. 
The following program uses a custom function named rtrim() to remove the 
trailing spaces from a string. It carries out this action by iterating through 
the string backward, starting at the character before the terminating null 
character (0) and ending when it finds the first nonspace character. When the 
program finds a nonspace character, it sets the next character in the string to 
the terminating null character (0), thereby effectively eliminating all the 
trailing blanks. Here is how this task is performed: 
A switch statement is generally best to use when you have more than two 
conditional expressions based on a single variable of numeric type. For 
instance, rather than the code 
if (x == 1) 
printf("x is equal to one.n"); 
else if (x == 2) 
printf("x is equal to two.n"); 
else if (x == 3) 
printf("x is equal to three.n"); 
else 
printf("x is not equal to one, two, or three.n"); 
the following code is easier to read and maintain: 
switch (x) 
{ 
case 1: printf("x is equal to one.n"); 
break; 
case 2: printf("x is equal to two.n"); 
break; 
case 3: printf("x is equal to three.n"); 
break; 
default: printf("x is not equal to one, two, or three.n"); 
break; 
} 
1) arrays - I'm talking about C-language and Java-language arrays: fixed-sized, 
indexed, contiguous structures whose elements are all of the same type, and 
whose elements can be accessed in constant time given their indices. 
2) vectors - also known as "growable arrays" or ArrayLists. Need to know that 
they're objects that are backed by a fixed-size array, and that they resize 
themselves as necessary. 
3) linked lists - lists made of nodes that contain a data item and a 
pointer/reference to the next (and possibly previous) node. 
4) hashtables - amortized constant-time access data structures that map keys to 
values, and are backed by a real array in memory, with some form of collision
handling for values that hash to the same location. 
5) trees - data structures that consist of nodes with optional data elements and 
one or more child pointers/references, and possibly parent pointers, 
representing a heirarchical or ordered set of data elements. 
6) graphs - data structures that represent arbitrary relationships between 
members of any data set, represented as networks of nodes and edges. 
1) What are some really common data structures, e.g. in java.util? 
4) How do you print out the nodes of a tree in level-order (i.e. first level, 
then 2nd level, then 3rd level, etc.) 
Describe a function that takes an int value, and returns true if the bit pattern 
of that int value is the same if you reverse it (i.e. it's a palindrome); i.e. 
boolean isPalindrome(int x) 
Bad Sign #2: 
Me: So! What data structures do we have available to us, as programmers? 
Them: Arrays, queues, vectors, stacks, lists, um, linked lists... 
Me: OK, any others? 
Them: Um, doubly-linked lists, and, uh, array lists. 
Me: Have you ever used a tree? 
Them: Oh! (laughs) Yeah, um, I forgot about those. 
Me: So! What text-editor do you use? 
Them: Visual Studio. 
Me: OK. What about on Unix? 
Them: On Unix I use vi. 
Me: Er, yeah, vi is cool... ever used VIM? 
Them: No, just vi. Always worked just fine for me. 
http://cplus-interview-questions.blogspot.in/

More Related Content

What's hot

1212 regular meeting
1212 regular meeting1212 regular meeting
1212 regular meeting
marxliouville
 
Missilecommand
MissilecommandMissilecommand
Missilecommand
Susan Gold
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
MohammedShameer28
 
Arrays
ArraysArrays
Arrays
Juhi Kumari
 
Day 5a iteration and functions if().pptx
Day 5a   iteration and functions  if().pptxDay 5a   iteration and functions  if().pptx
Day 5a iteration and functions if().pptx
Adrien Melquiond
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked lists
Deepam Aggarwal
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
SaranyaK68
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Data types
Data typesData types
Data types
Syed Umair
 
Bc0038– data structure using c
Bc0038– data structure using cBc0038– data structure using c
Bc0038– data structure using c
hayerpa
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
pramodkumar1804
 
Structure in c
Structure in cStructure in c
Structure in c
Samsil Arefin
 
The awesome algorithm
The awesome algorithmThe awesome algorithm
The awesome algorithm
Sazzad Hossain
 
Implementation of “Parma Polyhedron Library”-functions in MATLAB
Implementation of “Parma Polyhedron Library”-functions in MATLABImplementation of “Parma Polyhedron Library”-functions in MATLAB
Implementation of “Parma Polyhedron Library”-functions in MATLAB
Leo Asselborn
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
Joyjit Choudhury
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
Sharad Dubey
 
Data structure
Data structureData structure
Data structure
Nida Ahmed
 
R data types
R   data typesR   data types
R data types
Learnbay Datascience
 
Unit 4
Unit 4Unit 4

What's hot (19)

1212 regular meeting
1212 regular meeting1212 regular meeting
1212 regular meeting
 
Missilecommand
MissilecommandMissilecommand
Missilecommand
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
 
Arrays
ArraysArrays
Arrays
 
Day 5a iteration and functions if().pptx
Day 5a   iteration and functions  if().pptxDay 5a   iteration and functions  if().pptx
Day 5a iteration and functions if().pptx
 
Dynamic memory allocation and linked lists
Dynamic memory allocation and linked listsDynamic memory allocation and linked lists
Dynamic memory allocation and linked lists
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Data types
Data typesData types
Data types
 
Bc0038– data structure using c
Bc0038– data structure using cBc0038– data structure using c
Bc0038– data structure using c
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Structure in c
Structure in cStructure in c
Structure in c
 
The awesome algorithm
The awesome algorithmThe awesome algorithm
The awesome algorithm
 
Implementation of “Parma Polyhedron Library”-functions in MATLAB
Implementation of “Parma Polyhedron Library”-functions in MATLABImplementation of “Parma Polyhedron Library”-functions in MATLAB
Implementation of “Parma Polyhedron Library”-functions in MATLAB
 
An Introduction to the C++ Standard Library
An Introduction to the C++ Standard LibraryAn Introduction to the C++ Standard Library
An Introduction to the C++ Standard Library
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Data structure
Data structureData structure
Data structure
 
R data types
R   data typesR   data types
R data types
 
Unit 4
Unit 4Unit 4
Unit 4
 

Similar to I1

Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
University of Salerno
 
RegexCat
RegexCatRegexCat
RegexCat
Kyle Hamilton
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
ShwetaPandey248972
 
Matlab intro
Matlab introMatlab intro
Matlab intro
THEMASTERBLASTERSVID
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
konkatisandeepkumar
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
ssuser772830
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
Rajmohan Madasamy
 
C Interview Questions for Fresher
C Interview Questions for FresherC Interview Questions for Fresher
C Interview Questions for Fresher
Javed Ahmad
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
sonu sharma
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
Kgr Sushmitha
 
C interview Question and Answer
C interview Question and AnswerC interview Question and Answer
C interview Question and Answer
Jagan Mohan Bishoyi
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
University of Salerno
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
Kushaal Singla
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
Sowri Rajan
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
Max Kleiner
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
J'tong Atong
 
Format string
Format stringFormat string
Format string
Vu Review
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
Bryan O'Sullivan
 
06 linked list
06 linked list06 linked list
06 linked list
Rajan Gautam
 
Manipulating string data with a pattern in R
Manipulating string data with  a pattern in RManipulating string data with  a pattern in R
Manipulating string data with a pattern in R
Lun-Hsien Chang
 

Similar to I1 (20)

Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
RegexCat
RegexCatRegexCat
RegexCat
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
C Interview Questions for Fresher
C Interview Questions for FresherC Interview Questions for Fresher
C Interview Questions for Fresher
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
C interview Question and Answer
C interview Question and AnswerC interview Question and Answer
C interview Question and Answer
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Format string
Format stringFormat string
Format string
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
06 linked list
06 linked list06 linked list
06 linked list
 
Manipulating string data with a pattern in R
Manipulating string data with  a pattern in RManipulating string data with  a pattern in R
Manipulating string data with a pattern in R
 

Recently uploaded

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 

Recently uploaded (20)

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 

I1

  • 1. What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used? The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character (0) has been moved. On the other hand, the memcpy() function is designed to work with any type of data. Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination. The following program shows examples of both the strcpy() and the memcpy() functions: . How can I remove the trailing spaces from a string? The C language does not provide a standard function that removes trailing spaces from a string. It is easy, however, to build your own function to do just this. The following program uses a custom function named rtrim() to remove the trailing spaces from a string. It carries out this action by iterating through the string backward, starting at the character before the terminating null character (0) and ending when it finds the first nonspace character. When the program finds a nonspace character, it sets the next character in the string to the terminating null character (0), thereby effectively eliminating all the trailing blanks. Here is how this task is performed: A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code if (x == 1) printf("x is equal to one.n"); else if (x == 2) printf("x is equal to two.n"); else if (x == 3) printf("x is equal to three.n"); else printf("x is not equal to one, two, or three.n"); the following code is easier to read and maintain: switch (x) { case 1: printf("x is equal to one.n"); break; case 2: printf("x is equal to two.n"); break; case 3: printf("x is equal to three.n"); break; default: printf("x is not equal to one, two, or three.n"); break; } 1) arrays - I'm talking about C-language and Java-language arrays: fixed-sized, indexed, contiguous structures whose elements are all of the same type, and whose elements can be accessed in constant time given their indices. 2) vectors - also known as "growable arrays" or ArrayLists. Need to know that they're objects that are backed by a fixed-size array, and that they resize themselves as necessary. 3) linked lists - lists made of nodes that contain a data item and a pointer/reference to the next (and possibly previous) node. 4) hashtables - amortized constant-time access data structures that map keys to values, and are backed by a real array in memory, with some form of collision
  • 2. handling for values that hash to the same location. 5) trees - data structures that consist of nodes with optional data elements and one or more child pointers/references, and possibly parent pointers, representing a heirarchical or ordered set of data elements. 6) graphs - data structures that represent arbitrary relationships between members of any data set, represented as networks of nodes and edges. 1) What are some really common data structures, e.g. in java.util? 4) How do you print out the nodes of a tree in level-order (i.e. first level, then 2nd level, then 3rd level, etc.) Describe a function that takes an int value, and returns true if the bit pattern of that int value is the same if you reverse it (i.e. it's a palindrome); i.e. boolean isPalindrome(int x) Bad Sign #2: Me: So! What data structures do we have available to us, as programmers? Them: Arrays, queues, vectors, stacks, lists, um, linked lists... Me: OK, any others? Them: Um, doubly-linked lists, and, uh, array lists. Me: Have you ever used a tree? Them: Oh! (laughs) Yeah, um, I forgot about those. Me: So! What text-editor do you use? Them: Visual Studio. Me: OK. What about on Unix? Them: On Unix I use vi. Me: Er, yeah, vi is cool... ever used VIM? Them: No, just vi. Always worked just fine for me. http://cplus-interview-questions.blogspot.in/