C / C++ Code Portfolio



Download 112,15 Kb.
bet1/30
Sana01.03.2022
Hajmi112,15 Kb.
#475852
  1   2   3   4   5   6   7   8   9   ...   30
Bog'liq
dddd


C / C++ Code Portfolio
Pointers
Memory Handling
Function Pointers
Bit Operations
File Handling
Headers and Inline Functions
Class Example
Operator Overloading
Inheritance and Virtual Functions
Templates
Function Overloading
Recursion
STL
Example: Linked List
Example: Queue
This page contains C and C++ programming samples written by me, web site author Chris Berger. The purpose of this portfolio is to demonstrate my coding style and proficiency with C and C++.
Pointers
// This function returns the number of elements in a string

#include // "header" file that defines size_t type

size_t MyStrlen(const char *s1) // declare function myStrlen
{
const char *returnAddress = s1; // declare pointer to first element of s1
while (*s1++) // use while loop to simply increment pointer
{
if (!*s1) // if null character is encountered...
{
return (size_t)(s1 - returnAddress); // return the length of s1
}
}
return 0; // this return statement should never be executed
} // end function myStrlen
// This function lexigraphically compares two strings

int MyStrcmp(const char *s1, const char *s2)
{
do
{
if (*s1 > *s2) // if the char in s1 is greater than the char in s2
{
return 1; // s1 is lexigraphically greater than s2, return 1
}
else if (*s1 < *s2) // if the char in s1 is less than the char in s2
{
return -1; // s1 is lexigraphically less than s2, return -1
}
else // s1 is lexigraphically equal to s2, need to evalute more
continue;
} while ((*s1++ != '\0') && (*s2++ != '\0')); // increment the char to evaluate unless '\0' is found
// if the loop exists without returning a value, that means the strings were the same until '\0' was
// encountered in both, which means the strings are lexigraphically equal, return 0


Download 112,15 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4   5   6   7   8   9   ...   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish